I am having a problem using hidden() to generate hidden fields in forms. Here is a swatch of code to demonstrate my problem:
#!/usr/bin/perl use warnings; use strict; use CGI qw/ :standard /; print hidden( -name => "foo", -default => "bar", ), "\n";
When I run this code with the `foo' parameter defined, I get bad results. For example:
> ./hidden.pl # the code above <input type="hidden" name="foo" value="bar" /> > ./hidden.pl foo=123 <input type="hidden" name="foo" value="123" />
The value of the hidden input changes based on the pre-existing values. I see that one can use hidden() to retrieve values but I simply want to define a new one at this point. The `hidden ( $name, $value )' usage functions in the same way.

Perldoc says:
Note, that just like all the other form elements, the value of a hidden field is "sticky". If you want to replace a hidden field with some other values after the script has been called once youll have to do it manually: $query->param(hidden_name,new,values,here);
Destroying CGI parameters in order to insert hidden fields does not seem reasonable to me. There must be a bettery way. Is there a way to overcome this problem simply? And is there some reasoning behind the way things currently are?

Thanks in advance.

In reply to Hidden fields using CGI by narse

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.