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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It is true that CGI has sticky form elements by default. Your problem is that nobody has explained exactly what is meant, in this situation, by "sticky form elements." So let me give it a shot.

At a basic level, CGI.pm's stickiness consists of exactly this: when you submit a form, via GET or POST, to a script that uses the functions (or methods) defined in the module CGI both to parse its input and to generate a new form in its output, then form elements in the output that have the same name as form elements that were parsed as part of the input will, unless otherwise specified (usually using the -value and -force arguments to the code-generating method or subroutine), be pre-populated with the values that they had in the incoming GET or POST request.

Clear as mud? Was afraid of that...

To put it in more relevant terms for you: for your form to be pre-populated with the values from a previous invocation, the script has to get those values from the browser when it's called. So your strategy of having a separate script to validate, with a simple hard-coded link back to the original script for corrections, cannot possibly work. However, you have various options that can work, with greater or lesser amounts of work on your part:

  1. Combine your validation and correction scripts. That is, instead of having one script issue the form and another validate its inputs, have one script that does both. Then, instead of a link back to the original form, you simply print some explanatory message ("Your input was missing values Y, Z, and X"), and print the form again. This will get you your sticky values automatically (assuming you're using CGI to print out your form elements, of course).
  2. Change the link back from the validation page to the input page from a hard-coded one to a dynamic one that includes the parameters you wish to have your input page pre-populated with. There are a couple of ways to do this, using the URI module or the messing around with the self_url method of your CGI object, none of which I really like very much or use often enough to be able to write an example off the cuff. Sorry.
  3. You can create a form on the validation page that does roughly the same job, only making the browser and CGI do all the work for you. Then instead of a link back, you'll have a submit button. This one I am willing to illustrate (though I don't necessarily endorse it):
    my $hidden_form = $cgi->start_form( -name=>"resubmission, -method=>"POST", -action=>$input_cgi_location, ); foreach my $p ($cgi->param) { $hidden_form .= $cgi->hidden($p); } $hidden_form .= $cgi->submit( -name=>"resubmitted", -value=>"Return to input form", ); $hidden_form .= $cgi->end_form;
    (Please note that the above is not in any way tested.)

I hope some of that was helpful—good luck!



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders


In reply to Re: Sticky Forms by ChemBoy
in thread Sticky Forms by JsnHendry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found