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

I writing a CGI script for the first time
I can not find a way to program a reset form to Defaults Values
I can program it with a defaults button $query->defaults('Defaults'),and when the user hits that button it works fine.
But i don't want the user to press a button it want to invoke it from my program.
How can I program this?
Thank you for your help
Harry

Replies are listed 'Best First'.
Re: CGI.PM automaticly reset form to Defaults
by almut (Canon) on Jan 14, 2007 at 15:48 UTC

    Not entirely sure what you mean by ... want to invoke it from my program, but my Crystal Ball tells me you might have the following scenario :)

    You're repeatedly calling the same CGI script (as, for example, to enter multiple data records into some DB, with each form submit providing the data for a single record...), and you want to keep CGI.pm from setting the values of the previous submit as start values in the next form presented to the user.

    If that's the case, the method delete_all() might be what you're looking for. Just execute it before outputting the form -- after having processed the parameters from the previous submit, of course.

      No i have made a script that searches /var/www/html/bestellingen/ingezet/ for files
      it displays the files and then the user has three options
      do nothing (niets)
      place the file in /var/www/html/bestellingen/postvak_uit (verzenden)
      or place the file in /var/www/html/bestellingen/nakijken (nakijkeną
      The script works fine but when i push the submit (verwerken) button the screen needs to refresh and that does not work i have a set to defaults button when i push it everything is ok
      Here is my code it is probably the ugliest code you ever seen but i'm not a programmer and new to perl

        (Note: I have that sneaking suspicion it was you, harryC, who downvoted me (for trying to help), so you'll understand that my follow-up response is somewhat less verbose than it would be otherwise...   UPDATE: it turned out my suspicion was wrong. I'm sorry for that!)

        So, yes, I do think you more or less have the scenario I decribed: you do not specify an "action" URI when you call start_form, so CGI.pm will submit to itself (the default), i.e. the URI that generated the page/form...   and thus put the parameters received as initial values into the subsequent form on the response page (this is default magic of CGI.pm).

        What you want is: extract the parameters you need (like $verwerken = param('Doorsturen'), etc.), then call $q->delete_all. Both needs to be done before you output the form with $q->start_form .

        Alternatively, in particular if you don't really want the form at all on the response page, specify -action => $some_other_URI as argument to start_form(), and generate the response page via some other CGI script...

Re: CGI.PM automaticly reset form to Defaults
by SFLEX (Chaplain) on Jan 14, 2007 at 13:04 UTC
    I writing a CGI script for the first time

    Even though CGI.pm has a lot of functions for html and forms, I tend to still use my own html. Only because its easyer for me that way.

    May I suggest to use your own html in the parts where your having problems then maybe try to convert the script to use all CGI.pm's functions later.
    <input type="reset" name="Reset" value="Reset">

    Good Luck

Re: CGI.PM automaticly reset form to Defaults
by SFLEX (Chaplain) on Jan 14, 2007 at 13:44 UTC
    for CGI.pm you can try this for a Rest Button like the one in my post above.
    $query->reset('Reset Form') = <input type="reset"  name="Reset Form" value="Reset Form" />
    The code your using is just a submit button
    $query->defaults('Defaults') = <input type="submit" name=".defaults"  value="Defaults" />

    Good Luck

      with $query->defaults('Defaults') = <input type="submit" name=".defaults"  value="Defaults" />
      i get following error
      can't modify non-lvalue subroutine call
      thanks for your reply