Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

Populating the form

by peacemaker1820 (Pilgrim)
on Jul 03, 2002 at 15:12 UTC ( [id://179273]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

peacemaker1820 has asked for the wisdom of the Perl Monks concerning the following question:

HI Monks!
This is the code I have so far:
print "HTTP/1.0 200 OK\n"; print "Content-Type: text/html\n\n"; print "<HTML><HEAD><TITLE></TITLE></HEAD><BODY>"; use CGI; use LWP::Simple; use URI::URL; $url = url('File_Containing_form'); $url -> query_form(text1=>'my_name', text2=> 'my_lastName); $html = get($url); print $html; print "</BODY></HTML>"

When this script executes, I have a form that i retrieved from another file. How can I put my own values in this new form when it loads?

Thanks brothers

Replies are listed 'Best First'.
Re: Populating the form
by metadatum (Scribe) on Jul 03, 2002 at 15:46 UTC
Re: Populating the form
by termix (Beadle) on Jul 03, 2002 at 15:50 UTC

    I am assuming you want to show this form on a browser with some values filled in. To do this, you will need to modify the stuff returned from the get($url) call (in the $html variable). There seem to be two approaches I can think of to do this.

    If the form file is in your control, you can put in special tags (like $$USERID$$) and simply do a pattern match "substitution" to replace them with your values. Hence the form file will contain:

    <input type=text name=userid value="$$USERID$$">

    And you will use something like (untested!):

    $userid="123"; $html =~ s/\$\$USERID\$\$/$userid/g;

    And it becomes

    <input type=text name=userid value="123">

    There are HTML Template libraries that can help you do this and much much more. So try reusing those rather than coming up with your own replacement scheme if this is a sizeable project.

    If the form is not in your control, you will need to parse the form (using module like HTML::Parser or HTML::TokeParser) to find the "input" tags and then switch the value parameter with ones of your own choice. There are examples in the documentation (man pages and Internet sites) that you can use.

    -- termix

Re: Populating the form
by peacemaker1820 (Pilgrim) on Jul 03, 2002 at 16:03 UTC
    <html> <head> <title>name</title> </head> <body> <form name=formName action="cgibin/name1.pl" method="POST"> <p>my name is: <input type="text" name="text1" size="15"> <p>My lastName is: <input type="text" name="text2" size=15> </form> </body> </html>

    edited: Thu Jul 4 21:30:18 2002 by jeffa - added code tags

Re: Populating the form
by metadatum (Scribe) on Jul 03, 2002 at 16:14 UTC
    Then you would use HTML::Defaultify like so:
    $output = "<html> <head> <title>name</title> </head> <body> <form name +=formName action="cgibin/name1.pl" method="POST"> my name is: <input type="text" name="text1" size="15"> My lastName is: <input type="text" name="text2" size=15> </form> </bod +y> </html>" $def_output = defaultify($output, text1 => "John Smith", text2 => "Smith" }
    Then $def_output would contain your code, with the proper value= tags set.
Re: Populating the form
by impossiblerobot (Deacon) on Jul 03, 2002 at 19:00 UTC
    I use HTML::FillInForm, an object-oriented module that uses HTML::Parser to do the actual parsing, and can take the data to insert into the form from a variety of sources, including CGI.pm objects.

    Impossible Robot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://179273]
Approved by FoxtrotUniform
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.