function regcode_user in Registration codes 5
Same name and namespace in other branches
- 5.3 regcode.module \regcode_user()
- 6.2 regcode.module \regcode_user()
- 6 regcode.module \regcode_user()
Act on user account actions.
Parameters
$op: The type of action is being performed.
$edit: The array of form values submitted by the user.
$account: The user object on which the operation is being performed.
$category: The active category of user information being edited.
Return value
This varies depending on the operation.
File
- ./
regcode.module, line 106 - regcode.module
Code
function regcode_user($op, &$edit, &$account, $category = NULL) {
// Get the array of registration codes.
$regcodes = variable_get('regcode_codes', '');
// Only do the checking if the codes variable is set.
if (strlen(trim($regcodes))) {
switch ($op) {
case 'register':
// Inject the registration code field into the registration form.
$form['regcode_code'] = array(
'#type' => 'textfield',
'#title' => t('Registration Code'),
'#required' => TRUE,
'#description' => t('Please enter your registration code.'),
);
return $form;
case 'validate':
if ($category == 'account' && !$account->uid) {
// Make sure that the entered code is in the list.
$regcodes = explode("\n", $regcodes);
array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
if (!in_array(trim($edit['regcode_code']), $regcodes)) {
form_set_error('regcode_code', t('Invalid registration code'));
watchdog('regcode', t('User entered invalid registration code: ') . $edit['regcode_code'], WATCHDOG_WARNING);
}
}
break;
}
// switch
}
}