27 February 2021

How to create custom error in Wordpress without a plugin?

 Create custom error in WordPress without a plugin

    

 global $reg_errors;

    $reg_errors = new WP_Error;

    $person_name=$_POST['person_name'];

    $useremail=$_POST['useremail'];

    $password=$_POST['password'];

    

    

    if(empty( $useremail ) || empty($password))

    {

        $reg_errors->add('field', 'Required form field is missing');

    }    

 

    if ( !is_email( $useremail ) )

    {

        $reg_errors->add( 'email_invalid', 'Email id is not valid!' );

    }

    

    if ( email_exists( $useremail ) )

    {

        $reg_errors->add( 'email', 'Email Already exist!' );

    }

    if ( 5 > strlen( $password ) ) {

        $reg_errors->add( 'password', 'Password length must be greater than 5!' );

    }

    

    if (is_wp_error( $reg_errors ))

    { 

        foreach ( $reg_errors->get_error_messages() as $error )

        {

             $signUpError='<p style="color:#FF0000; text-aling:left;"><strong>ERROR</strong>: '.$error . '<br /></p>';

        } 

    }

    

    

    if ( 1 > count( $reg_errors->get_error_messages() ) )

    {



}



  <?php if(isset($signUpError)){echo '<div>'.$signUpError.'</div>';}?>

No comments:

Post a Comment

How to create multi step form with validations?

Create multi step form with validations  <!DOCTYPE html> <html lang="en"> <head>   <meta charset="UTF-8...