I have a simple Drupal 7 form, with 3 dropdown select lists and a submission button. I want to add another button to the form which does some function (but not submitting the form). I want to bypass the validation part for the form and directly run the submission handler of that button.
The button I am using is the following one.
$form['my_fieldset']['click'] = array(
'#type' => 'button',
'#value' => 'click me',
'#limit_validation_errors' => array(),
'#executes_submit_callback' => FALSE,
'#submit' => array('my_module_click_submit'),
);
FYI, all the select lists have #required=>TRUE
, and #type=>'submit'
for the button also doesn't work.
When I click it, it shows the error about the fields being required. How can I avoid that error, avoid validation handlers are run, and just run the code in my_module_click_submit()
?
Also, I dont know why, but even if I fill the entire form and then click this button, the page just gets refreshed and my_module_click_submit()
does NOT run. What's wrong?
I haven't put anything fancy inside my_module_click_submit()
; I just wanted to see if it works. The submission handler I am trying is the following one.
function my_module_click_submit($form,&$form_state) {
drupal_set_message('Click me button is clicked');
}
'#type' => '#submit',
?