admin管理员组

文章数量:1389889

As you can see on this link:

/video-upload/

after click submit button, wp says me e-mail is invalid but I enter valid e-mail.

Array ( [email_valid] => Email has no valid value )

related code:

  if(is_email($email)) {
            $error['email_valid'] = "Email has no valid value";
        }

full code:

<?php
/* Template Name: Video Upload */

get_header();

    global $wpdb;

    if ($_POST) {

        $username = $wpdb->escape($_POST['txtUsername']);
        $email = $wpdb->escape($_POST['txtEmail']);
        $password = $wpdb->escape($_POST['txtPassword']);
        $ConfPassword = $wpdb->escape($_POST['txtConfirmPassword']);

        $error = array();
        if (strpos($username, ' ')!==FALSE) {
            $error['username_space'] = "Username has Space";
        }
        if(empty($username)) {
            $error['username_empty'] = "Needed Username must";
        }
        if(username_exists($username)) {
            $error['username_exists'] = "Username already exists";
        }
        if(is_email($email)) {
            $error['email_valid'] = "Email has no valid value";
        }
        if(email_exists($email)) {
            $error['email_existence'] = "Email already exists";
        }
        if (strcmp($password, $ConfPassword) !==0) {
            $error['password'] = "Password didn't match";
        }
        if (count($error) == 0) {
            wp_create_user($username,$password,$email);
            echo "User created successfully";
            exit();
        }
        else print_r($error);
    }

?>

        <form method="post">

    <p>
            <label for="txtUsername">Enter Username</label>
        <div>
            <input type="text" id="txtUsername" name="txtUsername" placeholder="Username"/>
        </div>
    </p>

    <p>
        <label for="txtEmail">Enter Email</label>
    <div>
        <input type="email" id="txtEmail" name="txtEmail" placeholder="Email"/>
    </div>
    </p>

    <p>
        <label for="txtPassword">Enter Password</label>
    <div>
        <input type="password" id="txtPassword" name="txtPassword" placeholder="Password"/>
    </div>
    </p>

    <p>
        <label>Enter Confirm Password</label>
    <div>
        <input type="password" id="txtConfirmPassword" name="txtConfirmPassword" placeholder="Confirm Password"/>
    </div>
    </p>
        <input type="submit" name="btnSubmit"/>
</form>

<?php get_footer(); ?>

As you can see on this link:

https://cixme.deniz-tasarim.site/video-upload/

after click submit button, wp says me e-mail is invalid but I enter valid e-mail.

Array ( [email_valid] => Email has no valid value )

related code:

  if(is_email($email)) {
            $error['email_valid'] = "Email has no valid value";
        }

full code:

<?php
/* Template Name: Video Upload */

get_header();

    global $wpdb;

    if ($_POST) {

        $username = $wpdb->escape($_POST['txtUsername']);
        $email = $wpdb->escape($_POST['txtEmail']);
        $password = $wpdb->escape($_POST['txtPassword']);
        $ConfPassword = $wpdb->escape($_POST['txtConfirmPassword']);

        $error = array();
        if (strpos($username, ' ')!==FALSE) {
            $error['username_space'] = "Username has Space";
        }
        if(empty($username)) {
            $error['username_empty'] = "Needed Username must";
        }
        if(username_exists($username)) {
            $error['username_exists'] = "Username already exists";
        }
        if(is_email($email)) {
            $error['email_valid'] = "Email has no valid value";
        }
        if(email_exists($email)) {
            $error['email_existence'] = "Email already exists";
        }
        if (strcmp($password, $ConfPassword) !==0) {
            $error['password'] = "Password didn't match";
        }
        if (count($error) == 0) {
            wp_create_user($username,$password,$email);
            echo "User created successfully";
            exit();
        }
        else print_r($error);
    }

?>

        <form method="post">

    <p>
            <label for="txtUsername">Enter Username</label>
        <div>
            <input type="text" id="txtUsername" name="txtUsername" placeholder="Username"/>
        </div>
    </p>

    <p>
        <label for="txtEmail">Enter Email</label>
    <div>
        <input type="email" id="txtEmail" name="txtEmail" placeholder="Email"/>
    </div>
    </p>

    <p>
        <label for="txtPassword">Enter Password</label>
    <div>
        <input type="password" id="txtPassword" name="txtPassword" placeholder="Password"/>
    </div>
    </p>

    <p>
        <label>Enter Confirm Password</label>
    <div>
        <input type="password" id="txtConfirmPassword" name="txtConfirmPassword" placeholder="Confirm Password"/>
    </div>
    </p>
        <input type="submit" name="btnSubmit"/>
</form>

<?php get_footer(); ?>
Share Improve this question asked Mar 20, 2020 at 13:45 Excalibur SwordExcalibur Sword 1 5
  • 1 Well, what are you entering for an email that would throw that kind of error? – Howdy_McGee Commented Mar 20, 2020 at 13:50
  • Looks like you're missing the ! - if ( ! is_email() ) – Sally CJ Commented Mar 20, 2020 at 13:56
  • 1 @SallyCJ thanks, you are right. – Excalibur Sword Commented Mar 20, 2020 at 13:59
  • @SallyCJ I will similiar custom page for video upload.How can call my own variables from this page? Can you look at: wordpress.stackexchange/questions/361055/… – Excalibur Sword Commented Mar 20, 2020 at 14:27
  • @ExcaliburSword, I hope you don't mind I edited your answer. – Sally CJ Commented Mar 20, 2020 at 15:53
Add a comment  | 

1 Answer 1

Reset to default 0

I was just missing the "not" operator (!) in my conditional (if(is_email($email))), which in turn resulted in valid email addresses being treated as invalid. So I added the ! and that solved the problem:

// code before; incorrect - missing the !
if(is_email($email)) {
    $error['email_valid'] = "Email has no valid value";
}

// code after; working as expected after I added the !
if(! is_email($email)) { // if email is invalid, add the error message
    $error['email_valid'] = "Email has no valid value";
}

本文标签: functionsisemail gives me error