[development] Forms API and multiple submit buttons
Rob Barreca
rob at electronicinsight.com
Mon Nov 20 08:42:28 UTC 2006
>
> I need a way to determine which button was the one actually pressed.
In Drupal 5.0 you should be able to do something like if
($form_values['op'] == t('Button text')) {... (was only $_POST['op'] in
4.7 IIRC) in _validate and _submit to find which button was pressed.
Rob Roy Barreca
Founder and COO
Electronic Insight Corporation
http://www.electronicinsight.com
rob at electronicinsight.com
Syscrusher wrote:
> Okay, I've looked in the docs and at some of the Drupal core modules, but I
> haven't been able to get this to work.
>
> I need to have a Drupal 4.7/5.0 form that has multiple submit buttons. I want
> each button to invoke the hook_validate() and hook_submit() functions, but I
> need a way to determine which button was the one actually pressed.
>
> Code like this is what I initially tried in my form:
>
> $form = array(
> .... stuff ....
> 'button1' => array(
> '#type' => 'submit',
> '#value' => t('Foo'),
> ),
> 'button2' => array(
> '#type' => 'submit',
> '#value' => t('Bar'),
> ),
> );
>
> Now, both buttons work, but the form values array has both of their values.
>
> I tried using #default_value and #return_value instead of #value, but it seems
> not to change anything.
>
> Is there a better way to do this?
>
> Thanks!
>
> Scott (Syscrusher)
>
>
More information about the development
mailing list