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

Playing around with my first web app using the above. I am at the point now where I need to decide whether to have one form multi-tasking between query, submit and modify mode - or define the same form multiple times in run mode functions.

I am using Template Toolkit with CGI::Formbuilder and I cant work out how to reference the multiple buttons generated from the CGI::Formbuilder initialization param

submit => [qw/Submit Modify Query Delete Cancel/],
The doc refs state  [% form.submit %] as the placeholder for a submit button. You can also ref them by name as in  [% form.field.[name] %]. But the name of all the submit buttons is _submit.

I can get around this by redefining the form each time in a different run mode and only having one submit button. Is there a better solution. Simon

Replies are listed 'Best First'.
Re: CGI::FormBuilder Multiple Submit buttons and CGI::Application
by shenme (Priest) on Nov 12, 2003 at 00:49 UTC
    You can have multiple submit buttons, but let CFB figure out which one was used.   I don't remember my investigations on this, but my code ended up using
    if( $form->submitted ) { if( $form->submitted eq 'Cancel' ) { return $self->mainmenu_form_generate( undef ); } if( $form->submitted eq '< Back' ) { # User wants to return to previous form return $self->upload2_form_generate( undef ); } ... other code to process 'Continue' button ... }
    Remember that CFB has specified
    <input type="submit" name="_submit"  value="Next >"
        onClick="this.form._submit.value = this.value;">
    
    to capture which button was clicked.   So it consults the one name to get the value.

    If I remember right CFB will substitute _all_ the HTML for all submit buttons when you reference [% form.submit %].   I think this is one reason I switched to generating my own buttons using an included TT2 file, not using CFB.   I wanted a particular layout and CFB just lumped them all together.

    In general, the more specific I got about the screen handling, the less useful CFB was for me.   This is not unexpected if I read the author's comments correctly.

    Since you are thinking about a cancel button on the same form, remember you may need to 'evade' the normal form error-checking when that button is clicked.

    my $JSNoValdtnOnCancelBack = <<EOJSFUNC; if (form._submit.value == 'Cancel') { // skip validation since we're cancelling return true; } EOJSFUNC ... later ... $o .= $form->render( template => { type => 'TT2', ::::: }, jsfunc => $JSNoValdtnOnCancelBack, );
      Thanks
Re: CGI::FormBuilder Multiple Submit buttons and CGI::Application
by jdtoronto (Prior) on Nov 12, 2003 at 03:13 UTC
    CGI::Formbuilder is a great tool for very fast prototyping and simple application development. The author of the mopdule has a website devoted to it and it has a very useful tutorial on it:

    formbuilder.org

    There is also a mailing list available from that site and I have found others as well as the author very willing to help.

    Yes, you can use multiple submit buttons, and you name each one and you can retrieve the value in the submitted() function. If you have specified multiple submit buttons then they are ALL placed at once using the form.submit template variable. I cannot comment on Template Toolkit, because I only use this module with HTML::Template (but also within CGI::Application).

    Good luck! jdtoronto