나는 선언 된 동일한 페이지에 게시하는 양식이 있습니다. 문제는 제출 될 때 두 번 호출되는 것처럼 보입니다. 여기 코드는 다음과 같습니다두 번 호출되는 PHP 양식 게시
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="[email protected]" 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;
}
문제는 invalidate_email()
두 번 호출되는 것입니다. 비록 양식이 제출 된 후에야 만 $_POST["action"] == "update_user_data"
때만 화재가 발생합니다. 두 번째 전화가 어디에서 왔는지는 알 수 없습니다.
function invalidate_email($user_id, $new_email) {
$key = createKey($new_email);
$activation_url = get_permalink(get_page_by_title('Activate'))."?key=".$key."&id=".$user_id."&type=email";
update_user_meta($user_id, 'new_email', $new_email);
update_user_meta($user_id, 'email_activation_key', $key);
$expires = get_metadata("user", $user_id, "email_expires", true);
if (!$expires) {
$expires = time() + 86400000; //86400000 milliseconds = 24 Hours
update_user_meta($user_id, 'email_expires', $expires);
}
$message = "A request to update your email for your account on First steps has been made, please confirm your email address by clicking the following link: <p />";
$message .= "<a href='".$activation_url."'>".$activation_url."</a> <p />";
$message .= "If you did not request the change your account may be comprimised and we recommend you change your password from the 'my account' page. <p />";
$message .= "If you do not confirm your new email address within 24 hours the request will expire and you will have to request a new one.";
email($new_email, "First steps - Confirm your new email address", "Confirm email address change", $message);
}
및 email()
: 여기
invalidate_email()
기능입니다 나는 그것이 Ajax 호출되지 않습니다 긍정적 인 생각
function email($to, $subject, $heading, $message, $attachments = NULL) {
$headers = array('From: First steps <[email protected]>', 'Content-type: text/html');
$body = '<table width="100%" style="background:#ECECEC;" cellpadding="0" cellspacing="0">
<tr width="100%" style="background: #3393b5;">
<td align="center">
<table width="500" cellpadding="0" cellspacing="0">
<tr>
<td align="center" style="height:45px; vertical-align:middle;">
<a href="'.get_bloginfo("url").'"><img alt="First steps for health care assistants" src="'.get_stylesheet_directory_uri().'/library/images/logo.png" width="347" height="32" style="vertical-align:middle;display:block;" /></a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" style="padding: 10px 0px;">
<table width="500" style="padding: 10px;background:#FFFFFF;border:1px solid #BCBCBC;margin:0px 10px;" cellpadding="0" cellspacing="0">
<tr>
<td style="color:#000000;font-size:14px;line-height:1.5em;text-align:left;"><font face="verdana">
<h2 style="margin-top: 0.1em; font-size: 18px; padding-bottom: 0.5em; color: #333333; border-bottom: 1px solid #CCCCCC; margin-bottom: 0.7em;">'.$heading.'</h2>
'.$message.'
</font></td>
</tr>
</table>
<table width="500">
<tr>
<td style="font-size:12px;line-height:1.5em;text-align:left;"><font face="verdana">We are committed to keeping your email private, we do not share your address with third-parties.</font></td>
</tr>
</table>
</td>
</tr>
</table> ';
wp_mail($to, $subject, $body, $headers, $attachments);
}
(그래서 add_ajax_validation()
무시) 내가 아약스 검증을 제거하는 경우에도 발생하기 때문에 (이것은이 기능이하는 것입니다). 또한 Ajax가 헤더가 있어야 jQuery에 의해 수행되기 때문에 존재해야하는 HTTP_X_REQUESTED_WITH
의 존재를 확인했습니다.
는 편집 : 응답에서이
내가 무슨 일이 함수를 호출 한보기 위해debug_backtrace()
을 수행 @Oli하기 위해, 여기 내 역 추적입니다 :
$trace= debug_backtrace();
$funcs = array();
foreach ($trace as $func) {
array_push($funcs, $func['function']);
}
$funcs = implode('\n', $funcs);
출력 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 :
,210call_user_func()
에서이 이상은 다음의 모든 함수 호출의 결과로 워드 프레스 CMS에 의해 이루어집니다 : add_shortcode('user_data_form', 'user_data_form', 134);
우리에게 invalidate_email() 함수를 보여주세요 – Duniyadnd
@Duniyadnd 업데이트 된 질문 –
감사합니다. 이제 email() 함수를 보여 주겠다고 부탁합니다. mail() 함수가 호출되는 곳을 추측하겠습니다. – Duniyadnd