[html-formfu] Multiple submit buttons redux: What am I doing wrong?

Jeff Dairiki dairiki at dairiki.org
Fri Aug 7 23:01:41 GMT 2009


Hi All,

I have what I suspect is a stupid question.

I've recently upgraded from HTML:FF 0.03001 to 0.05001.

On Thu Mar  5 09:16:08 2009 fireartist at gmail.com (Carl Franks) wrote:
> 009/2/17 Greg Coates <greg at coatesoft.com>:
> > I think I might have found a bug. ?I have HTML::FormFu version 0.03007
> > installed. ?Here's what's happening.
> >
> > I created a form that ends with the following 3 submit buttons:
> > ---
> >   - type: Submit
> >     name: submit
> >     value: Save for Later
> >   - type: Submit
> >     name: submit
> >     value: Finish
> >   - type: Submit
> >     name: submit
> >     value: Cancel
> >
> > These display as expected. ?However, if the form is submitted, contains
> > errors, and then is re-displayed, the buttons all contain the same text.
> > Here's the HTML that is generated:
> >
> > <input name="submit" type="submit" value="Save for Later" />
> > <input name="submit" type="submit" value="Save for Later" />
> > <input name="submit" type="submit" value="Save for Later" />
> >
> > All the values get set to the same value for some reason.
>
> I've fixed this in svn by changing the Button element.
> Instead of setting retain_default(1), it now sets force_default(1)

That's the change that bit me.

I'd been using multiple submit buttons with different names, e.g.

  - type: Submit
    name: submitted
    value: Save
  - type: Submit
    name: cancelled
    value: Cancel

then checking param_value, e.g.:

  $form->process($cgi);
  if ($form->param_value('cancelled')) {
    # redirect to home page...
  }

With force_default set, $form->param_value('cancelled') seems to always
return 'Cancel', whether or not that was the button that was actually hit.
(Is that really what's supposed to happen?  My naive guess would be that
that force_default would only affect the (re)rendering of the form, and
not have any effect on values returned by param_value, et al.)

With force_default set on the submit buttons, is there a way to tell
which button was hit using just the $form object, or do I now have to
look directly the submitted parameters, e.g. $cgi->param('cancelled')?

(For now, I've used default_args to set retain_default and clear
force_default on Submit buttons, but I'd like to know what the
spiritually correct "FormFu way" is for implementing multiple submit
buttons.)

Jeff



More information about the HTML-FormFu mailing list