You are here

function regcode_form_user_register_form_alter in Registration codes 7

Same name and namespace in other branches
  1. 8 regcode.module \regcode_form_user_register_form_alter()
  2. 7.2 regcode.module \regcode_form_user_register_form_alter()

Implements hook_form_FORM_ID_alter().

File

./regcode.module, line 167
Main functionality and hooks of regcode module.

Code

function regcode_form_user_register_form_alter(&$form, &$form_state) {
  $code_optional = variable_get('regcode_optional', FALSE);
  $form['regcode'] = array(
    '#type' => 'textfield',
    '#title' => check_plain(variable_get('regcode_field_title', t('Registration Code'))),
    '#description' => check_plain(variable_get('regcode_field_description', t('Please enter your registration code.'))),
    '#required' => !($code_optional || user_access('administer users')),
    '#element_validate' => array(
      'regcode_code_element_validate',
    ),
  );

  // Capture the code from the url and inject it into the registration form.
  if (isset($_GET['regcode'])) {

    /*
     * Form API can handle potentially unsafe characters as long as they are
     * not printed directly. This code gets trimmed in regcode_code_validate().
     */
    $form['regcode']['#value'] = $_GET['regcode'];
    $form['regcode']['#description'] = NULL;
    $form['regcode']['#disabled'] = TRUE;
  }
}