Passing an extra element to $edit array when creating an account I added an extra user registration validation critera in my custom module by implementing hook_user

if ('validate' == $op &amp;&amp; 'user_register' == $edit['form_id'] &amp;&amp; 'account' == $category &amp;&amp; !$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' =&gt; $account['pass'],
      'pass2' =&gt; $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(&amp;$form, &amp;$form_state, $form_id)  { 
  if ($form_id == 'user_register') {
    $form['remote_create_user'] = array('#type' =&gt; 'value', '#value' =&gt; 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.
If you are actually trying to prevent a user from registering with an email that is in use, Drupal already has that built in. It also has a check that prevents users with an IP in the blocked IP address list to create an account.

Solution

Your flaw in the above code is that drupal_execute calls drupal_process_form which will rebuild the $form_state['values']. A solution could be to add a hidden/value form element to the user_register form with hook_form_alter. Doing that should allow you to send your custom value through drupal_execute.