0

I added 2 items to the user registration form Phone Number and Carrier. When I register a user or edit one i get the following error. Notice: Undefined property: stdClass::$phone in user_account_form() (line 1066 of /var/www/capaug/modules/user/user.module). Notice: Undefined property: stdClass::$carrier in user_account_form() (line 1076 of /var/www/capaug/modules/user/user.module).

Here is the code for the user registration:

function user_account_form(&$form, &$form_state) {
  global $user;

  $account = $form['#user'];
  $register = ($form['#user']->uid > 0 ? FALSE : TRUE);

  $admin = user_access('administer users');

  $form['#validate'][] = 'user_account_form_validate';

  // Account information.
  $form['account'] = array(
    '#type'   => 'container',
    '#weight' => -10,
  );
  // Only show name field on registration form or user can change own username.
  $form['account']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#maxlength' => USERNAME_MAX_LENGTH,
    '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
    '#required' => TRUE,
    '#attributes' => array('class' => array('username')),
    '#default_value' => (!$register ? $account->name : ''),
    '#access' => ($register || ($user->uid == $account->uid && user_access('change own username')) || $admin),
    '#weight' => -10,
  );

  $form['account']['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address'),
    '#maxlength' => EMAIL_MAX_LENGTH,
    '#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
    '#required' => TRUE,
    '#default_value' => (!$register ? $account->mail : ''),
  );

  //Phone Number Entry
  $form['account']['phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone Number'),
    '#maxlength' => PHONE_MAX_LENGTH,
    '#description' => t('A valid Telephone number. Numbers only, no parentheses or dashes.'),
    '#required' => TRUE,
    '#default_value' => (!$register ? $account->phone : ''),
  );

  //Carrier Selection
  $form['account']['carrier'] = array(
    '#type' => 'select',
    '#title' => t('Carrier'),
    '#options' => array(t('--- NONE ---'), t('AT&T'), t('NTelos'), t('Sprint'), t('Straight-    Talk'), t('T-Mobile'), t('Tracfone'), t('Verizon'), t('Virgin Mobile')),
    '#description' => t('Your phone service provider. Select "None" for home phones.'),
    '#required' => TRUE,
    '#default_value' => (!$register ? $account->carrier : ''),
  );

Where do I have to define those variables to get them to work?

Thank you all!

2

Never, ever patch core like that. This is not how Drupal works. That said, you didn't specify whether you are using Drupal 7 or not; I presume you do. Instead of doing this, use the field UI module to add the relevant fields to users under Administer > Configuration > People > Profiles.

  • Drupal 7. ANd how can I pull the information and combine it for a list of users in a certain role? Is it possible (once they have registered) to call the phone and carrier for every user in a list? – JDSlimz Jul 26 '14 at 22:24
  • You want the Views module for the list. You really, really need to read more documentation or a book (shop.oreilly.com/product/0636920010890.do) on Drupal, these are very basic questions. As for calling... put up a different question. Finally, plz accept my answer if it was useful. – user49 Jul 27 '14 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.