0

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 ?

0

I have done below changed above code:

$form['#validate'] = array('useredit_user_pass_validation');

by

$form['#validate'][] = 'useredit_user_pass_validation';

And it's works !

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.