[html-formfu] Multiple Submits
Moritz Onken
onken at houseofdesign.de
Wed Aug 15 14:43:32 GMT 2007
There is a little bug. If you do it as I wrote the value of the
unclicked button will be "" after submission. If you have an error on
that form the new page will have an empty submit button.
$form->add_valid( $_->name, $_->value )
for ( @{ $form->get_elements( { type => 'submit' } ) }
this code fixes this problem.
Moritz Onken schrieb:
> Found a better way:
> Only the value name pair of the button you click on gets submitted.
>
> ---
> elements:
> - type: submit
> name: submit_next
> value: Localized Value + next
> - type: submit
> name: submit_back
> value_loc: Localized Value + back
>
> if ( $form->param( 'submit_next' ) ) {
> # go on
> }
> elsif ( $form->param( 'submit_back' ) ) {
> # go back
> }
>
> Does the Job pretty good
>
> Thanks anyway!
>
> Carl Franks schrieb:
>> 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
>>
>> _______________________________________________
>> HTML-FormFu mailing list
>> HTML-FormFu at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
More information about the HTML-FormFu
mailing list