Hook_user (): adding an additional field to the database of not only the form

I can add an additional field for registration. I need to know what step I need to take in order to then capture this input and paste it into drupal user table. The code below in my module only adds a field to the form, but when it is submitted it does nothing with the data.

function perscriptions_user($op, &$edit, &$account, $category = NULL){
  if ($op == 'register') {
    $form['surgery_address'] = array (
      '#type' => 'textarea',
      '#title' => t('Surgery Address'),
      '#required' => TRUE,
    );      

     return $form;     
  }

  if ($op == 'update') {
    // …
  }
}
+3
source share
1 answer

As stated in the hook_user () documentation :

$op . ( ):
 - "insert": . NULL $edit.
 - "update": . NULL $edit.
 - "validate": . , .

hook_install().

hook_user() , :

function perscriptions_user($op, &$edit, &$account, $category = NULL){
  if ($op == 'register' || ($op == 'form' && $category = 'account')) {
    $form['surgery_address'] = array (
      '#type' => 'textarea',
      '#title' => t('Surgery Address'),
      '#required' => TRUE,
    );

    return $form;     
  }

  if ($op == 'insert' || $op == 'update') {
    prescriptions_save_user_profile($account->uid, $edit['surgery_address']);
  }
  if ($op == 'validate' && $category == 'account') {
    // Verify the entered values are valid.
    // In this example, the value is contained in $edit['surgery_address'].
  }
}

prescriptions_save_user_profile() - , . , , .

+7

Source: https://habr.com/ru/post/1756744/


All Articles