I added an extra user registration validation critera in my custom module by implementing hook_user
if ('validate' == $op && 'user_register' == $edit['form_id'] && 'account' == $category && !$edit['remote_create_user']) {
// Is the mail address OK?
if ($email_in_use) {
// No, set error on mail form field
form_set_error('mail', t('Your email address is already associated with a account.'));
}
I added the !$edit['remote_save']
because I don't want this extra validation if I am creating accounts programmatically. The code I am using to create accounts is
$form_state['values'] = $account;
$form_state['values']['pass'] = array(
'pass1' => $account['pass'],
'pass2' => $account['pass'],
);
$form_state['values']['op'] = t('Create new account');
$form_state['values']['remote_create_user'] = TRUE;
$ret = drupal_execute('user_register', $form_state);
As you can see, I tried to add an extra form element called 'remote_save' $form_state['values']['remote_save'] = TRUE;
. However, in the hook code above $edit['remote_save'] is empty so I can't use it to stop the extra validation. How can I pass a value from $form_state to the $edit array? Or is there a better way to do this?
EDIT: So I tried to use hook_form_alter with the code below
function module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register') {
$form['remote_create_user'] = array('#type' => 'value', '#value' => FALSE);
}
}
However this code $form_state['values']['remote_create_user'] = TRUE;
which is in a separate module, does not set the value of $edit['remote_create_user']. The value of $edit['remote_create_user'] is still false.