Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get info from HTML without object names or number

Status
Not open for further replies.

random260

Programmer
Mar 11, 2002
116
US
Is it possible to do this? I have a couple of hundred HTML forms that I want to write 1 script to handle. Can perl cgi
get information from the HTML WITHOUT knowing the field name ahead of time? I would like to param the email address on the form (which is always in the email field, so I know that name), then just have the cgi script get everyting else from top to bottom. So if I have a form that has

email jdoe@me.here
kids 3
pet dog
computer dell optiplex
isp AOL

I use param to get the email address, then the script gets the name of the fields and the value of the fields and saves them to a file, so I can see not only the field value but the field name. Oh, and just to make it more interesting, there are a different number of fields on every form, so how do I deal with the dreaded "premature end of script header" error if the script can deal with 20 fields and the form only has 15? The main thing I need to know is CAN this be done? If so, then a sample of ONLY the code needed to get the field names and values would be great.

Thanks
Steve
 
Yes, it can be done. My question to you is what are you going to do with the information after you parse it into hash tables. If the script doesn't know what the field names are then how will it know how to processing the unknown data?

There's always a better way. The fun is trying to find it!
 
As long as I can mate the field info with the field name I'm good, because it is just going to get written to a file. I just need them mated because if I ask (for example)

fieldname dogsname (user enters buster)
fieldname kidsname (user enters skippy)

Then I need to know which name goes to the dog and which goes to the kid. So the file will simply contain 1 line for each fieled - the name of the field and the value of the field, written like

dogsname buster
kidsname skippy

Thanks!
Steve
 
Code:
#!/usr/bin/perl
use strict;
use CGI;
my $cgi_obj = new CGI;
print $cgi_obj->header,
    $cgi_obj->start_html;

my @params = $cgi_obj->param;
print '<ul>';
foreach (@params) 
  {
  my $value = $cgi->param($_);
  print &quot;<li>$_ : $value</li>\n&quot;;
  }
print '</ul>',
    $cgi_obj->end_html;

I think that works.... 'haven't run it. ;-)

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top