in reply to CGI::FormBuilder Multiple Submit buttons and CGI::Application

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, );

Replies are listed 'Best First'.
Re: Re: CGI::FormBuilder Multiple Submit buttons and CGI::Application
by set_uk (Pilgrim) on Nov 12, 2003 at 11:28 UTC
    Thanks