Fix for Fix for Why isn't my submit function being called?

  1. /**
  2.  * Menu callback. Defines a form for adding and editing people (users).
  3.  */
  4. function people_edit() {
  5.   $args = @func_get_arg(0);
  6.   // If a uid has been passed, pass it on to the form builder function.
  7.   return $args ? drupal_get_form('people_edit_form', $args) : drupal_get_form('people_edit_form');
  8. }
  9.  
  10. function people_edit_form($form_state) {
  11.   // Check whether a uid has been passed to the function via a URL argument.
  12.   // If so, load the user.
  13.   $uid = @func_get_arg(1);
  14.   if ($uid) {
  15.     if (!is_numeric($uid) || !$person = user_load($uid)) {
  16.       drupal_set_message('The person could not be found.', 'error');
  17.       drupal_goto('people');
  18.     }
  19.   }
  20.   if (!$uid) {
  21.     $person = NULL;
  22.     $persona = NULL;
  23.   } else {
  24.     // $persona = person array. Creates an array for passing to functions.
  25.     $persona = (array)$person;
  26.     drupal_set_title(t('Edit @person-name', array('@person-name' => check_plain($person->profile_name_first . ' ' . $person->profile_name_last))));
  27.   }
  28.   $op = $uid ? 'form' : 'register';
  29.  
  30.   // Copied from user.module:
  31.   // Create a dummy variable for pass-by-reference parameters.
  32.   $null = NULL;
  33.    
  34.   // Get a list of profile categories and sort them
  35.   $categories = module_invoke_all('user', 'categories', $null, $person);
  36.   uasort($categories, '_user_sort');
  37.  
  38.   // Generate form items by category by invoking hook_user()
  39.   $form = array();
  40.   foreach ($categories as $category) {
  41.     $form = array_merge($form, module_invoke_all('user', $op, $persona, $person, $category['name']));
  42.     $form[$category['name']]['#collapsible'] = TRUE;
  43.     $form[$category['name']]['#collapsed'] = TRUE;
  44.   }
  45.  
  46.   // Get rid of fields that don't apply to the people module
  47.   unset($form['theme_select'], $form['locale'], $form['account']);
  48.  
  49.   $form['submit'] = array(
  50.     '#type' => 'submit',
  51.     '#value' => t('Save'),
  52.     '#weight' => 10,
  53.     '#submit' => 'people_edit_form_submit', // you may have another submit on your code. In that case you have to specify the submit callback function
  54.   );
  55.      
  56.   return $form;
  57. }
  58.  
  59. /**
  60.  * Submit handler for the people editing form.
  61.  */
  62. function people_edit_form_submit($form, &$form_state) {
  63.   echo 'test';
  64. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.