in reply to Re: How to get unselected radio_group() items after submitting form
in thread How to get unselected radio_group() items after submitting form

Interesting! Yes, Miller, that worked, much as I hate hard coding... :-)

Thanks also to Wallisds for a more official solution.

Scott
  • Comment on Re^2: How to get unselected radio_group() items after submitting form

Replies are listed 'Best First'.
Re^3: How to get unselected radio_group() items after submitting form
by wind (Priest) on Mar 09, 2011 at 04:18 UTC

    If you look at the source code of CGI, you can discover the code inside end_form that is adding all the extra hidden variables.

    sub end_form { my($self,@p) = self_or_default(@_); if ( $NOSTICKY ) { return wantarray ? ("</form>") : "\n</form>"; } else { if (my @fields = $self->get_fields) { return wantarray ? ("<div>",@fields,"</div>","</form>") : "<div>".(join '',@fields)."</div>\n</fo +rm>"; } else { return "</form>"; } } }

    As you can see above, the $NOSTICKY global will prevent the extra hidden fields that lead to the undesired default values. After reading the documentation of $NOSTICKY, you can set this in two different ways. One of them is more global:

    use CGI qw(-nosticky);

    Or you can is isolate the change to just the end_form function by doing the following:

    print do {local $CGI::NOSTICKY = 1; $q->end_form()} . "\n";

    Or you can just simplify the whole process for yourself by writing a simple </form> tag. Really don't know why someone wouldn't just do that anyway as the CGI module really does try to do too much in my opinion.

    - Miller