Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've added a custom input field with login_form hook.

So, I need to process the post data to validate. I've used the lostpassword_post for lostpassword_form and works great, but I cant find a hook to validate my data at login form.

Any Ideas?

share|improve this question

2 Answers 2

Use the action 'login_init' to catch all calls to wp-login.php.

Sample code:

add_action( 'login_init', 'wpse_51227_validate_custom_field' );

function wpse_51227_validate_custom_field()
{
    if ( ! isset ( $_POST['special_custom'] )
        return;

    if ( ! is_numeric( $_POST['special_custom'] )
        // handle the error
}

There are two important global variables available:

  • $errors is an instance of WP_Error. Maybe you want to use it to store error data.
  • $action is the current action. Maybe you want to rest it to login to prevent a redirect if the user input is invalid.
share|improve this answer

Haven't really tested this but I'm just guessing by how I do it with the registration & profile pages.

Try something like this:

function my_login_errors( $errors ) {
    if ( empty( $_POST['custom_field'] ) )
        $errors->add( 'empty_custom_field', '<strong>ERROR</strong>: Please enter some info.' );
    return $errors;
}
add_filter( 'login_errors', 'my_login_errors' );

Note: Modify the custom_field part and the message accordingly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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