Connecting Tech Pros Worldwide Help | Site Map

hidden variables with EncType="multipart/form-data"

Newbie
 
Join Date: Aug 2007
Posts: 22
#1: Jul 26 '09
Not able to pass variables data:

Hello .. Im building a form that uploads files with encType="multipart/form-data" but on the same form I need to pass other variables with hidden fields.

The files are uploading fine but Im not getting the values of the hidden fields,

How can I get hidden field values along with uploaded files in the same form..??

This is my form code:


Expand|Select|Wrap|Line Numbers
  1. <form action="upload_file.pl" encType="multipart/form-data" method="Post">
  2. <input type=file name="FILE">
  3. <input type="hidden" name="URL" value="$URL">
  4. <input type="hidden" name="Alias" value="$Alias">
  5. <INPUT type=submit value="Upload File">
  6. </form>
Im attaching the perl script that handles the upload under the name of Upload_Perl_Script.txt

Thanx beforehand
Virtual Web
Attached Files
File Type: txt Upload_Perl_Script.txt (11.9 KB, 68 views)
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#2: Jul 26 '09

re: hidden variables with EncType="multipart/form-data"


Quote:

Originally Posted by virtualweb View Post

Not able to pass variables data:

Hello .. Im building a form that uploads files with encType="multipart/form-data" but on the same form I need to pass other variables with hidden fields.

The files are uploading fine but Im not getting the values of the hidden fields,

How can I get hidden field values along with uploaded files in the same form..??

This is my form code:


Expand|Select|Wrap|Line Numbers
  1. <form action="upload_file.pl" encType="multipart/form-data" method="Post">
  2. <input type=file name="FILE">
  3. <input type="hidden" name="URL" value="$URL">
  4. <input type="hidden" name="Alias" value="$Alias">
  5. <INPUT type=submit value="Upload File">
  6. </form>
Im attaching the perl script that handles the upload under the name of Upload_Perl_Script.txt

Thanx beforehand
Virtual Web

I see your above form code and I have a question. Is that code being sent to the browser by a Perl script, or is it just an HTML file? If it is a Perl script, can we see it as well?

If they are not set, then I assume there is an issue with your variables being set as shown above and you should look into that first to ensure they are being set.

Regards,

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Jul 26 '09

re: hidden variables with EncType="multipart/form-data"


That script is written to get only numbered file upload fields. How are you getting $URL and $ALIAS into that form you posted anyway?
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Jul 26 '09

re: hidden variables with EncType="multipart/form-data"


assuming your form is populated correctly:

change this:

Expand|Select|Wrap|Line Numbers
  1.     use CGI; 
  2.  
  3.     $max_num_files  ||= 1;
  4.     $Data         ||= $ENV{'DOCUMENT_ROOT'};
  5.     undef @bad_extensions if @good_extensions;
change to:

Expand|Select|Wrap|Line Numbers
  1.     use CGI; 
  2.  
  3.     $max_num_files  ||= 1;
  4.     $Data         ||= $ENV{'DOCUMENT_ROOT'};
  5.     undef @bad_extensions if @good_extensions;
  6.     $alias = $req->param("Alias");
  7.     $url = $req->param("URL");
  8.  
now you use $url and $alias in the perl script however you need them.
Newbie
 
Join Date: Aug 2007
Posts: 22
#5: Jul 26 '09

re: hidden variables with EncType="multipart/form-data"


Hi KevinADC:

I appreciate your help.. I had tryed your solution prior to posting for help here, and it didnt work. This made me think that uploading a file was different than passing text as a variable.

Second time around worked just fine..

Thanx a million
VirtualWeb
Reply