Solved

Problem reeding form entries with perl

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 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