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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem parsing HTML form elements

Status
Not open for further replies.

bijuperl

Programmer
Apr 11, 2002
6
0
0
IN
I want to parse the form elements in a HTML file to fetch their key/value pairs. I have written the following code using ActivePerl for Windows -->

use HTTP::Request::Common;
use HTML::Form;

$htmlfilename = "/defaults.shtml";
$ipaddress = " //This is an imaginary URL
@forms = HTML::Form->parse($htmlfilename, $ipaddress);
$x = @forms;
print "size of \@forms = $x";

But this code prints the size of @forms as zero. What is the problem here?
I am very new to perl so do not know if this kinda code would ever work. If it does not, then can anyone tell me, how do I obtain the key/value pairs for all form elements in a HTML file. Some working, sample code would be very useful.
 
smells like hw, but I'll take the bait anyway.
Code:
#!/usr/local/bin/perl -T
use strict;
use CGI;
my $q = new CGI;
print $q->header,
    $q->start_html,
    $q->Dump,
    $q->end_html;

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
do u means that u need a function
to read $buffer from a <form> submit
matching spliting name and values
if so say YES THAT IS !!!!
and il give u a function for this
using no modules
waiting for your reply
 
Hi hereugo,
Can u please give me that function that can parse the HTML Form elements and give me the key-value pairs.
Thanx in advance
 
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
$wanted = $FORM{theinput};
if ($wanted == 0 ) {# ....

html..
<input name=&quot;theinput&quot; value=&quot;0&quot;>

was that what u need ?
i was &quot;hereugo&quot; someone knowledge ends were
someone else knowledge starts
 
Hi,
This is not what i wanted.Please note that I'm using ActivePerl for Windows modules.
My problem is:
I'm setting some values in a HTTP Server thru the GUI,which is nothing but a web page.I'm able to set values in the server using the perl script that i have written:
It looks like this:
-----------------------------
use HTTP::Request::Common;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->request(POST ' [ nest_printer_name => 'mon',
start_page_enable => 'Off',
FpMenuLocked => 'Off',
help_ehandler => 'On',
estar_enabled => 'On',
front_panel_language => 'Fran\u&#231;ais',
nest_system_location => 'bijus cube',
nest_system_contact => 'christy',
wait_timeout => '200',
job_timeout => '300',
multipurpose_timeout => '1 Minute',
print_quality => 'Enhanced',
ImageSmoothing => 'On',
Duplex => 'Long Edge',
color_correction => 'None',
media_source => 'Tray 1']);
----------------------------------------
Now i want to get the values that i have just set,using another perl script so that i can compare the two and give a log file as to whether the values are correctly set or not.For that i'm using the script:
-------------------------------------------------
use HTML::Form;
$htmlfilename = &quot;/printerdefaults.shtml&quot;;
$ipaddress = &quot;@forms = HTML::Form->parse($htmlfilename, $ipaddress);

But the parse function is not populating the @array and i'm stuck here.
Is there any other modules in ActivePerl that i can use for doing the same?
Please send me some code..
 
Hi NeverSleep,
Ur code is reading the key/value pairs from the submit buffer.I don't wan't this.
See, when i submit the HTML page after setting some values in it and refresh the page,i get back the values that i had last set,and this comes from the server.
Now from this HTML page i want to extract the values that i had just set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top