phpdrupaldrupal-6drupal-fapidrupal-alter

Getting altered form values in drupal


I created one module in drupal name as newmodule.I use form alter to alter user registration form for adding one field location.When i submit the form, how i can get the value of the new field which i created .


Solution

  • To elaborate on the previous answers, somewhere in your hook_form_alter function, you want to tell the form to run your own #submit handler, e.g.:

    function mymodule_form_alter(&$form, &$form_state, $form_id) {
      $form['new_field'] = array( ... ); // You already did this, right?
      $form['#submit'][] = 'mymodule_submit_handler'; // Add this
    }
    

    Note: you should be appending on #submit here, not replacing it. Then in your submit handler, you can get the value easily, e.g.:

    function mymodule_submit_handler($form, &$form_state) {
      $value = $form_state['values']['new_field'];
    }