Regcode is a module which adds a registration code for user registrations. When using 3rd party authentication apps such as FBOAuth, the regcode field is not shown when it is required.

Comments

Silox’s picture

Showing the field is rather easy; put this code in the complete_profile.pages.inc

  // Support the regcode module
  if (module_exists('regcode')) {
    $code_optional = variable_get('regcode_optional', FALSE);

    $form['regcode']['regcode_code'] = array(
      '#type' => 'textfield',
      '#title' => variable_get('regcode_field_title', t('Registration Code')),
      '#description' => 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'),
    );
  }

Currently trying to set the field when editing information.

Silox’s picture

Actually validating the code is a bit harder. We overwrite the form submit function to trigger a custom function, where we check if the regcode module exists, and hack us a way to be able to use the defined helper function:

1. Change
$form['#submit'][] = 'user_profile_form_submit';
to
$form['#submit'][] = 'complete_profile_form_submit';

2. Add below

function complete_profile_form_submit($form, &$form_state) {
  // Regcode support
  if(module_exists('regcode')) {
    // Set regcode to used

    // Little hack to be able to use the regcode_use_helper here
    $regcode_array = array('regcode_code' => $form['regcode']['regcode_code']['#value']);
    regcode_use_helper($regcode_array, $form['#entity']);
  }

  // Submit the profile form
  return user_profile_form_submit($form, $form_state);
}
Silox’s picture

Status: Active » Needs review
StatusFileSize
new1.73 KB

Added patch