You are here

function twilio_user_settings_form in Twilio 7

User settings form.

1 string reference to 'twilio_user_settings_form'
twilio_user_settings in ./twilio.pages.inc
Menu callback for adding and confirming a user's mobile number.

File

./twilio.pages.inc, line 17
User facing pages

Code

function twilio_user_settings_form($form, &$form_state, $account) {
  if (isset($form_state['values']['account'])) {
    $account = user_load($form_state['values']['account']->uid);
  }
  $form['#prefix'] = '<div id="twilio-user-form">';
  $form['#suffix'] = '</div>';
  $form['uid'] = array(
    '#type' => 'hidden',
    '#value' => $account->uid,
  );
  if (empty($account->twilio_user['status'])) {
    $form['countrycode'] = array(
      '#type' => 'select',
      '#title' => t('Country code'),
      '#options' => twilio_country_codes(),
    );
    $form['number'] = array(
      '#type' => 'textfield',
      '#title' => t('Phone number'),
      '#description' => t('A confirmation code will be sent to via SMS to the number provided'),
      '#size' => 40,
      '#maxlength' => 255,
      '#required' => TRUE,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Confirm number'),
      '#validate' => array(
        'twilio_user_settings_add_form_validate',
      ),
      '#submit' => array(
        'twilio_user_settings_add_form_submit',
      ),
      '#ajax' => array(
        'callback' => 'twilio_user_settings_ajax_callback',
        'wrapper' => 'twilio-user-form',
        'method' => 'replace',
      ),
    );
  }
  elseif ($account->twilio_user['status'] == 1) {
    $form['number'] = array(
      '#type' => 'item',
      '#title' => t('Mobile phone number'),
      '#markup' => $account->twilio_user['number'],
    );
    $form['confirm_code'] = array(
      '#type' => 'textfield',
      '#title' => t('Confirmation code'),
      '#description' => t('Enter the confirmation code sent by SMS to your mobile phone.'),
      '#size' => 4,
      '#maxlength' => 4,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Confirm number'),
      '#validate' => array(
        'twilio_user_settings_confirm_form_validate',
      ),
      '#submit' => array(
        'twilio_user_settings_confirm_form_submit',
      ),
      '#ajax' => array(
        'callback' => 'twilio_user_settings_ajax_callback',
        'wrapper' => 'twilio-user-form',
        'method' => 'replace',
      ),
    );
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Delete & start over'),
      '#validate' => array(
        'twilio_user_settings_confirm_form_validate',
      ),
      '#submit' => array(
        'twilio_user_settings_confirm_form_submit',
      ),
      '#ajax' => array(
        'callback' => 'twilio_user_settings_ajax_callback',
        'wrapper' => 'twilio-user-form',
        'method' => 'replace',
      ),
    );
  }
  elseif ($account->twilio_user['status'] == 2) {
    $form['twilio_user']['number'] = array(
      '#type' => 'item',
      '#title' => t('Your mobile phone number'),
      '#markup' => '+' . $account->twilio_user['country'] . ' ' . $account->twilio_user['number'],
      '#description' => t('Your mobile phone number has been confirmed.'),
    );
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Delete & start over'),
      '#validate' => array(
        'twilio_user_settings_reset_form_validate',
      ),
      '#submit' => array(
        'twilio_user_settings_reset_form_submit',
      ),
      '#ajax' => array(
        'callback' => 'twilio_user_settings_ajax_callback',
        'wrapper' => 'twilio-user-form',
        'method' => 'replace',
      ),
    );
  }
  return $form;
}