Stop a custom submit button from firing the form validation on a CCK form

Posted by kidrobot on Stack Overflow See other posts from Stack Overflow or by kidrobot
Published on 2009-06-27T22:27:01Z Indexed on 2010/03/30 2:03 UTC
Read the original article Hit count: 527

Filed under:
|
|
|

I've added a submit button inside a fieldgroup on a CCK form using hook_form_alter as follows:

function mymodule_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'object_node_form') {

   $form['group_wikipedia']['search'] = array(

 '#type' => 'submit',
 '#value' => t('Search Wikipedia'),
 '#name' => 'searchwiki',
 '#submit' => array('mymodule_searchwiki_submit'),
   );

  }
}

When I press the button, the validation handlers for the full form eg. checks for required fields, run as though I have pressed the 'Submit' button at the end of the form.

I thought that changing the #name property from 'op' to 'searchwiki' would prevent this kind of mix-up, but not so.

Does anyone know a workaround for this?

© Stack Overflow or respective owner

Related posts about drupal

Related posts about cck