[html-formfu] Multiple Submits
Carl Franks
fireartist at gmail.com
Wed Aug 15 09:45:04 GMT 2007
On 14/08/07, Moritz Onken <onken at houseofdesign.de> wrote:
>
> I started today using FormFu and I just like it! Carl, you did a very
> good Job!
Thanks - I'm glad it's useful.
> But I ran into one problem. I want to use multiple submit buttons. The
> common way is, to set a value on each and check that value later to
> determine which has been clicked.
> That's fine asa long as your page is in only one language.
Could you not do something like:
if ( $form->param( 'submit_1' ), eq $form->loc( 'submit_1' ) ) {
# submit_1 pressed
}
elsif ( $form->param( 'submit_2' ), eq $form->loc( 'submit_2' ) ) {
# submit_2 pressed
}
That's assuming the form is created something like this:
---
elements:
- type: submit
name: submit_1
value_loc: submit_1
- type: submit
name: submit_2
value_loc: submit_2
The only potential problem I think think of with this approach is if:
* you're storing the user's language choice using a session or cookie
* after viewing the page containing the form, but before submitting the form...
* ...the user uses a 2nd browser window to change their language choice
You could prevent this by also storing the language choice in a hidden
field, and then doing $form->languages([ $form->param('lang') ])
before doing the 'eq' checks.
> I thought of a hidden field whose value is being changed on submitting
> (by JS).
> If there is no better way I will write an element for that and publish it.
I'd like to make sure that nothing in the core relies on JS for
functionality - so make sure you pick an appropriate namespace if you
write something like that.
For example, I've created a couple of elements in the
HTML::FormFu::Element::Dojo::* namespace which use the dojo javascript
library (although even these degrade gracefully and are usable without
JS).
See http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-Dojo/
Cheers,
Carl
More information about the HTML-FormFu
mailing list