?
Solved

Problem reeding form entries with perl

Posted on 2001-07-22
5
Medium Priority
?
177 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

771 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