http://www.perlmonks.org?node_id=189476

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

Hello gentle, fellow monks,

I've been writing a stock tracking/barcoding database for my boss (why I bothered to get a degree and a PhD to wind up doing this stuff I'll never know) and one of the 'features' he'd like to see is some kind of form reset on submission.

I've been using CGI.pm quite happily in a reasonably limited kind of way - I can happily reset a form with an appropriately labelled CGI.pm 'Reset' button, but what I want to do is when you hit 'Submit' I want the script to go away and do its magic and *then* reset the various textboxes etc to their default (null) values.

This is something I've been pondering for a while, how do I do this? Goddammit Jim I'm a biologist not a programmer...

Many thanks in advance,

Bukowski - aka Dan (dcs@black.hole-in-the.net)
"Coffee for the mind, Pizza for the body, Sushi for the soul" -Userfriendly

Replies are listed 'Best First'.
Re: CGI.pm form clearing
by ColtsFoot (Chaplain) on Aug 12, 2002 at 13:33 UTC
    Try setting -override=>1 as in the code below
    #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my $page = new CGI; print $page->header(); print $page->start_html(); print $page->startform(-method=>'POST'); print $page->textfield(-name=>'field1', override=>1); print $page->submit(-name=>'submit', -value=>'Submit'); print $page->endform(); print $page->end_html;
    the -override parameter is accepted by all methods that
    generate form elements.

    Hope this helps
Re: CGI.pm form clearing
by fruiture (Curate) on Aug 12, 2002 at 13:23 UTC

    perhaps you only want to delete_all() before outputting the form again?!

    --
    http://fruiture.de
Re: CGI.pm form clearing
by Ryszard (Priest) on Aug 12, 2002 at 13:25 UTC
    Use a template of your form. Read in your html file, spit it out to the screen... Nice and easy.

    You can do it quite easily and simply by reading the file in using standard IO techniques, or do something fancy using a templating system like HTML::Template.

    This also has the advantage of decoupling the html from your code... even better.

Re: CGI.pm form clearing
by gwhite (Friar) on Aug 12, 2002 at 14:11 UTC
    You can use the module HTML::FillInForm to drop in default values into the form.

    g_White