Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP表单post被调用两次_Php_Html_Forms_Post - Fatal编程技术网

PHP表单post被调用两次

PHP表单post被调用两次,php,html,forms,post,Php,Html,Forms,Post,我有一个表单发布到它声明的同一页。问题是,它在提交时似乎被调用了两次。代码如下: function user_data_form() { add_ajax_validation(); // Form verication start if (isset($_POST["action"])) { switch($_POST["action"]) { case "validate_form": aja

我有一个表单发布到它声明的同一页。问题是,它在提交时似乎被调用了两次。代码如下:

function user_data_form() {

    add_ajax_validation();

    // Form verication start
    if (isset($_POST["action"])) {
        switch($_POST["action"]) {
            case "validate_form":
                ajax_validate();
                break;
            case "update_user_data":
                $wp_user_object = wp_get_current_user();
                $id = $wp_user_object->ID;
                if ( 0 == $wp_user_object->ID ) {
                    redirect(get_permalink(get_page_by_title( 'Sign in' )), array(
                        "message" => 8
                    ));
                } else {
                    $form_data = array(
                        "verified" => false,
                        "email" => $_POST["email"],
                        "first_name" => $_POST["first_name"],
                        "last_name" => $_POST["last_name"],
                        "password" => $_POST["password"],
                        "old_password" => $_POST["old_password"],
                        "verify_password" => $_POST["verify_password"]
                    );
                    $form_data["verification"] = array(
                        "old_password" => wp_check_password($form_data["old_password"], $wp_user_object->user_pass, $id),
                        "email" => validate("email", $form_data["email"]),
                        "password" => validate("old_password", $form_data["old_password"]),
                        "verify_password" => validate("verify_password", $form_data["old_password"], $form_data["verify_password"])
                    );
                    if ($form_data["verification"]["old_password"]) {
                        if ($form_data["email"] != $wp_user_object->user_email && $form_data["verification"]["email"]) {
                            invalidate_email($id, $form_data["email"]);
                            $message = message('success', 'Account information updated, an email has been dispatched to <strong>'.$form_data["email"].'</strong> with details on how to confirm your new email address');
                            $form_data["email"] = $wp_user_object->user_email;
                        }
                        if ($form_data["first_name"] != $wp_user_object->get("first_name")) {
                            update_user_meta($id, 'first_name', $form_data["first_name"]);
                        }
                        if ($form_data["last_name"] != $wp_user_object->get("last_name")) {
                            update_user_meta($id, 'last_name', $form_data["last_name"]);
                        }
                        if ($form_data["verification"]["password"]["result"] && $form_data["verification"]["verify_password"]["result"]) {
                            wp_set_password($form_data["password"], $id);
                        }
                        if (!message) {
                            $message = message('success', 'Account information updated');
                        }
                    } else {
                        $message = message('error', '<b>Error:</b> Incorrect password');
                    }
                }
                break;
        }
    }
    // Form verication end

    // Create form
    if (!$form_data["verified"]) {
        global $current_user;
        get_currentuserinfo();
        $new_email = get_metadata("user", $current_user->user_ID, "new_email", true);
        $email_expires = get_metadata("user", $current_user->user_ID, "email_expires", true);
        $form = 'You can view and update your account settings using the following form:
                <form action="#" method="post" class="user-data">
                '.$message.'
                <input type="hidden" name="action" value="update_user_data" />
                <div class="fields">
                    <div class="field">
                        <label for="email">Email:</label>
                        <input type="text" name="email" id="email" class="text" data-validation-method="email" class="text" data-validation-ignore="'.encode($current_user->user_email).'" value="'.(($form_data["email"]) ? $form_data["email"] : $current_user->user_email).'" placeholder="youremail@somesite.com" data-validation-response="'.(($form_data["email"] == $current_user->user_email) ? NULL : encode($form_data["verification"]["email"])).'" />
                        '.(($new_email) ? '<span class="fail">An email has been sent to the above address to change email to <strong>'.$new_email.'</strong></span>' : NULL).'
                        <span class="info">You will recieve a validation email to your new email address. If you don\'t confirm within 24 hours your email address will revert to the last validated one.</span>
                    </div>
                    <div class="field">
                        <label for="first_name">First name: <sup>1</sup></label>
                        <input type="text" name="first_name" id="first_name" class="text" value="'.$current_user->user_firstname.'"/>
                        <label for="last_name">Last name: <sup>1</sup></label>
                        <input type="text" name="last_name" id="last_name" class="text" value="'.$current_user->user_lastname.'"/>
                        <span class="info"><sup>1</sup> Required to issue certificates.</span>
                        <div class="fieldgroup">
                            <span class="info">
                                <strong>Note:</strong> Only fill in these fields if you wish to change your password.
                            </span>
                            <div class="field">
                                <label for="password">New password:</label>
                                <input type="password" name="password" id="password" data-validation-method="password" class="text" value="'.$form_data["password"].'" data-validation-response="'.((strlen($form_data["password"]) > 0) ? encode($form_data["verification"]["password"]) : NULL ).'" />
                            </div>
                            <div class="field">
                                <label for="verify_password">Retype your new password:</label>
                                <input type="password" name="verify_password" id="verify_password" class="text" data-validation-method="verify_password" data-validation-requires="password" value="'.$form_data["verify_password"].'" data-validation-response="'.((strlen($form_data["verify_password"]) > 0) ? encode($form_data["verification"]["verify_password"]) : NULL ).'" />
                            </div>
                        </div>
                        <div class="field">
                            <label for="password">Current password:</label>
                            <input type="password" name="old_password" id="old_password" class="text" value=""/>
                            <span class="info">Your current password is required to make changes to your account information. Have you <a href="'.get_permalink( get_page_by_title( 'Reset your password' ) ).'">forgotten your password?</a></span>
                        </div>
                    </div>
                    <input type="submit" id="submitbtn" class="button omega" name="submit" value="Update my account information" />
                </div>
            </form>';
    } else {
        redirect(get_permalink(get_page_by_title( 'My account' )), array(
            "message" => 2
        ));
    }
    return $form;
}
电子邮件()

产出1:

invalidate_email
user_data_form
call_user_func
do_shortcode_tag
preg_replace_callback
do_shortcode
pre_process_shortcode
call_user_func_array
apply_filters
wp_trim_excerpt
call_user_func_array
apply_filters
get_the_excerpt
require_once 
load_template
locate_template
get_header
include
require_once
require
产出2:

invalidate_email
user_data_form
call_user_func
do_shortcode_tag
preg_replace_callback
do_shortcode
pre_process_shortcode
call_user_func_array
apply_filters
the_content
include
require_once
require
call\u user\u func()
及以后,由于以下函数调用,所有操作都由WordPress CMS完成:
add\u shortcode('user\u data\u form','user\u data\u form',134)

变量转储(func\u get\u args())
放入
无效电子邮件功能中,调查并检测您收到的参数。

我以前在mail()中注意到了这一点。如果在headers部分中有一个“To”,在mail()的第一个参数中有一个“To”变量,则会发送两次。您可能想删除标题的一部分,并尝试


我应该仔细阅读这个问题。

我觉得自己像个傻子,但我刚刚意识到这是自己造成的。我有一段代码试图避免WordPress的自动格式化功能
wpautop
。它似乎发射了他们两次

function pre_process_shortcode($content) {
    global $shortcode_tags;
    // Backup current registered shortcodes and clear them all out
    $orig_shortcode_tags = $shortcode_tags;
    $shortcode_tags = array();
        add_shortcode('registration_form', 'registration_form', 134);
        add_shortcode('login_form', 'login_form', 134);
        add_shortcode('user_data_form', 'user_data_form', 134);
        add_shortcode('activation_code', 'activation_code', 134);
        add_shortcode('logout_code', 'logout_code', 134);
        add_shortcode('reset_password_form', 'reset_password_form', 134);
    // Do the shortcode (only the one above is registered)
    $content = do_shortcode($content);
    // Put the original shortcodes back
    $shortcode_tags = $orig_shortcode_tags;
    return $content;
}

add_filter('the_content', 'pre_process_shortcode', 13);
我将此更改为:

    add_shortcode('registration_form', 'registration_form', 134);
    add_shortcode('login_form', 'login_form', 134);
    add_shortcode('user_data_form', 'user_data_form', 134);
    add_shortcode('activation_code', 'activation_code', 134);
    add_shortcode('logout_code', 'logout_code', 134);
    add_shortcode('reset_password_form', 'reset_password_form', 134);

这当然会产生其他问题,但至少它解决了这个问题,我会找到另一种方法来做我以前想做的事情。很抱歉,有人花时间试图解决此问题,因为根据我提供的信息,您永远无法解决此问题。

向我们展示函数invalidate_email()@Duniyadnd Updated question谢谢,现在我要要求展示email()函数-我猜这就是邮件()的位置正在调用函数。@Duniyadnd已更新问题。。。它调用
wp\u mail()
,这是WordPress CMS的内置功能,与您的问题无关,但我建议不要使用“global$current\u user;”它只接收要发送的参数-
$user\u id
$new\u email
。我不确定这有助于理解为什么它被调用了两次。请确保函数没有收到重复的函数,因此在此函数中之前没有收到重复的函数…抱歉,我不太理解。我认为您收到了两次,因为您从函数收到了两次。您收到2个参数,但未收到,因此,在此函数之前,它已通过。在这个函数之后,有些东西不起作用了。谢谢,但不仅仅是邮件被发送了两次,而且每次生成一个新的不同的
$activation\u url
时,这个函数都会被调用两次。
invalidate_email
user_data_form
call_user_func
do_shortcode_tag
preg_replace_callback
do_shortcode
pre_process_shortcode
call_user_func_array
apply_filters
the_content
include
require_once
require
function pre_process_shortcode($content) {
    global $shortcode_tags;
    // Backup current registered shortcodes and clear them all out
    $orig_shortcode_tags = $shortcode_tags;
    $shortcode_tags = array();
        add_shortcode('registration_form', 'registration_form', 134);
        add_shortcode('login_form', 'login_form', 134);
        add_shortcode('user_data_form', 'user_data_form', 134);
        add_shortcode('activation_code', 'activation_code', 134);
        add_shortcode('logout_code', 'logout_code', 134);
        add_shortcode('reset_password_form', 'reset_password_form', 134);
    // Do the shortcode (only the one above is registered)
    $content = do_shortcode($content);
    // Put the original shortcodes back
    $shortcode_tags = $orig_shortcode_tags;
    return $content;
}

add_filter('the_content', 'pre_process_shortcode', 13);
    add_shortcode('registration_form', 'registration_form', 134);
    add_shortcode('login_form', 'login_form', 134);
    add_shortcode('user_data_form', 'user_data_form', 134);
    add_shortcode('activation_code', 'activation_code', 134);
    add_shortcode('logout_code', 'logout_code', 134);
    add_shortcode('reset_password_form', 'reset_password_form', 134);