Submit Hanlder In Custom Drupal Forms

How to invoke two different functions from hook_form() in Drupal?
This can be achieved using submit handler.

Here is the explanation with code.
1:-Use following code in your hook_form() function:-

$form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',

        //here we are defining the first submit handler and
          calling one submit function
        '#submit' => array('test_form_submit'),
        );  


$form['enter'] = array(
        '#type' => 'submit',
        '#value' => t('Enter'),

        //here we are defining the second submit handler and
          calling second submit function
        '#submit' => array('enter_submit'),
        );

    
2:- By using  #submit =>  array('function_name'),you can call N number of functions from custom one form.
 

No comments:

Post a Comment