Solved

Problem reeding form entries with perl

Posted on 2001-07-22
5
174 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Automating a script for user accounts LINUX 14 77
how to pick specific file from ftp 13 70
How does Redux fit into React? 3 91
Select SamAccountName - powershell script 2 17
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

680 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