Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem reeding form entries with perl

Posted on 2001-07-22
5
Medium Priority
?
179 Views
Last Modified: 2013-12-25
I have this code that runs first when my cgi runs

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
@keys = ();
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    push(@keys, $name);
    $FORM{$name} = $value;
}

$first_name = $FORM{'first_name'};
$sur_name = $FORM{'sur_name'};
$user_name = $FORM{'user_name'};
$email_address = $FORM{'email_address'};
$user_id = $FORM{'user_id'};
$password = $FORM{'user_password'};
$description = $FORM{'description'};
$file = $FORM{'file'};

and here is the code for the forms

<form method="Post" action ="pagebuilder.pl?name=edit_account&action=save" onSubmit="return checknew(this.form)" name="newlogin" >
<table border="0" cellpadding="0" cellspacing="0" width="60%" height="262">
  <tr>
    <td width="50%" colspan="2" height="78">Please change the details
      below.
      <p>&nbsp;<p></td>
  </tr>
  <tr>
    <td width="50%" height="21">Your First Name:</td>
    <td width="50%" height="21"><textarea cols="40" rows = "1" name = "first_name">$first_name</textarea></td>
  </tr>
  <tr>
    <td width="50%" height="16">Your Sur Name:</td>
    <td width="50%" height="16"><textarea cols="40" rows = "1" name = "sur_name">$sur_name</textarea></td>
  </tr>
  <tr>
    <td width="50%" height="21">Your Password:</td>
    <td width="50%" height="21"><textarea cols="40" rows = "1" name = "user_password">$password</textarea></td>
  </tr>
  <tr>
    <td width="50%" height="21">Your Email Address:</td>
    <td width="50%" height="21"><textarea cols="40" rows = "1" name = "email_address">$email_address</textarea></td>
  </tr>
  <tr>
    <td width="50%" height="21">Enter a description of your self, this will apper in the forum and photo year book:</td>
    <td width="50%" height="21"><textarea name ="description" cols = "40" rows = "10">$description</textarea></td>
  </tr>          
  <tr>
    <td width="50%" height="21"><input type="submit" value="Commit Changes" name="B1"> </td>
    <td width="50%" height="21"></td>
  </tr>
<input type="hidden" name ="user_id" value ="$ucount">
</form>
  <tr height = "20"><td></td></tr>
  <tr>
    <td valign = "top">
     <form method="post" action="pagebuilder.pl?name=edit_account&action=save_image" enctype="multipart/form-data">
     Change your photo, select the file and click upload: <p>
     <input type="file" name="file" size=30><br>
     <input type="submit" value="Upload">
     </form>
    </td>
    <td valign = "top">
     <center>
     Your Current Image:<p>
     <image src = "$user_image" border="1" alt="$user_image_alt">
     </center>
    </td>    
  </tr>
  <tr>
    <td colspan = "2">
     <p>Please remember that you have a limit of 10KB for the image and only *.gif will work
    </td>
  </tr>
</table>

as you can see there are two forms that both call the same cgi, the proble i have is that the value of file is never set, it should be the value of the file box in the second form, what am i doing wrong, i am clicking on the second submit button that belongs to that form.

thanks kieran
0
Comment
Question by:kplonk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 150 total points
ID: 6306648
I don't believe that will work for files...

you will have to use the cgi module, and then I could help you.

Bob
0
 
LVL 10

Expert Comment

by:makerp
ID: 6308068
use the CGI module , it will make your life much easier. is standard in most perl distributions now days.

get it from CPAN or ActiveState if your using ActivePerl
0
 
LVL 2

Expert Comment

by:shirjeel
ID: 6309935
dear kplonk


use this code it will work for u wat ever fields u r using ok.

################################### code starts from here

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
     ($name, $value) = split(/=/, $pair);
     $value =~ tr/+/ /;
     $name =~ tr/+/ /;
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c",hex($1))/eg;
     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c",hex($1))/eg;
     $value =~ s/<!--(.|\n)*-->//g;
     $name =~ s/<!--(.|\n)*-->//g;
     $value =~ s/<([^>]|\n)*>//g;
     $name =~ s/<([^>]|\n)*>//g;
     $FORM{$name} = $value;
       print "$name = ((($FORM{$name})))<br>";
}

########################################
0
 

Author Comment

by:kplonk
ID: 6328642
Ok i have done this and all is well, did except this ages ago but the site did not keep it saved, how odd!!
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6328978
kplonk, are you sure you ment to accept my comment as an answer?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question