Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Unstickying CGI

by George_Sherston (Vicar)
on Aug 02, 2002 at 15:21 UTC ( [id://187125]=perlquestion: print w/replies, xml ) Need Help??

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

I have a site on which the user quite often fills in the same form with different info - fills in one form, submits it, and right away gets a new form. Now the default for CGI.pm, which is usually very useful, is that in this case the second form comes with the values submitted first time round. But in the present case that's not what I want. I'd like to be able to print out a whole load of empty fields (or sometimes fields with new info from a d.b.) as follows:
for (@Fields) { print $_->{Title}, ': ', textfield( -name => $_->{Name}, -value => $_->{Value}, ); }
... but as it is, I have resorted to:
for (@Fields) { param( -name => $_->{Field} , -value => $_->{Info}, ); print $_->{Title}, ': ', textfield( -name => $_->{Name}, -value => $_->{Value}, ); }
The -nosticky doesn't seem to do this for me (AFAIK it only works for hidden fields). Is there another way to turn off stickiness?

§ George Sherston

Replies are listed 'Best First'.
(jeffa) Re: Unstickying CGI
by jeffa (Bishop) on Aug 02, 2002 at 16:02 UTC
    You don't want -nosticky, you want -override. :)
      If you want to change the value of a field from its
      previous value, you have two choices:
    
      (1) call the param() method to set it.
    
      (2) use the -override (alias -force) parameter (a new
      feature in version 2.15).  This forces the default value
      to be used, regardless of the previous value:
    
        print $query->textfield(-name=>'field_name',
                                -default=>'starting value',
                                -override=>1,
                                -size=>50,
                                -maxlength=>80);
    

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Unstickying CGI
by sedhed (Scribe) on Aug 02, 2002 at 15:50 UTC

    The -nosticky option does not do quite what it sounds like it might. It just avoids the generation of special hidden cgi fields, but does not affect the stickyness of general form fields:

    -nosticky This makes CGI.pm not generating the hidden fields .submit and .cgifields. It is very useful if you don't want to have the hidden fields appear in the querystring in a GET method. For example, a search script generated this way will have a very nice url with search parameters for bookmarking.

    You're right, in order to avoid stickyness, you must set the value explicity. Either set it to undef or an empty string, or a specific new value in the case you mention above.

    cheers!

Re: Unstickying CGI
by kingman (Scribe) on Aug 02, 2002 at 17:33 UTC
    I got around the problem by print html strings like this:
    print "<input name=$name value=$value>\n";
    This won't be sticky.

      This is slightly offtopic and very nitpicky and may very well get me voted down but HTML should have quoted attribute values:

      print "<input name=\"$name\" value=\"$value\">\n";

      The same code written in XHTML 1.0:

      print "<input name=\"$name\" value=\"$value\" />\n";

        Also, I find that if you have to escape more then one quote, you're probably better off invoking qq{} with different delimiters, like <code>print qq{<input name="$name" value="$value" />

        (I almost always write XHTML; no good reason not too.) Also, you should be more careful if $name or $value potentialy contain quotes.


        Confession: It does an Immortal Body good.

Re: Unstickying CGI
by Stegalex (Chaplain) on Aug 02, 2002 at 19:05 UTC
    Instead of using the file extension of .cgi try using .html. It fixed this vexing problem for me recently.

    ~~~~~~~~~~~~~~~
    I like chicken.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://187125]
Approved by dimmesdale
Front-paged by dimmesdale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-03-29 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found