Question

I have altered Request new password form field label

function useredit_form_user_pass_alter(&$form, &$form_state, $form_id) {
  $form['name']['#title']='Username';
  $form['#validate'] = array('useredit_user_pass_validation');
}

function useredit_user_pass_validation($form, &$form_state) {

  $name = trim($form_state['values']['name']);
  if(preg_match("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/",$name))
  {
     form_set_error('parent_field_email', t('Please enter valid username.'));
  }
  # try to load by name.
  $users = user_load_multiple(array(), array('name' => $name, 'status' => '1'));
  $account = reset($users);

  if (isset($account->uid)) {
    form_set_value(array('#parents' => array('account')), $account, $form_state);
  }else{
    form_set_error('name', t('Sorry, %name is not recognized as a user name.', array('%name' => $name)));
  }
  }

form get's altered and validation works but captch image gets disappear. How to resolve this ?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top