Solved

Problem reeding form entries with perl

Posted on 2001-07-22
5
168 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
5 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 50 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now