0
我是wordpress新手,我必須在wordpress中創建自定義註冊表單。我聽說它可以用PHP和AJAX做。
我的代碼看起來像這樣的時刻:(在模板文件)在wordpress中的自定義註冊表格
jQuery(document).on("click", '.create-account-btn', function(){
var inputEmpty = false;
jQuery(".input__field--yoko").not("[type=submit]").each(function() {
if (jQuery.trim(jQuery(this).val()).length == 0) inputEmpty = true;
});
if (inputEmpty){
alert('Please fill all fields in the register form');
} else {
$.ajax({
type: "post",
url: "functions.php",
dataType: 'json',
data: {
action: "registerAccount",
username: $("#account-username").val(),
password: $("#account-password").val(),
email: $("#billing_email").val()
},
success:function() {
alert("I'm created!");
},
error: function() {
alert("Oh no, error! :(");
}
});
}
return false;
});
(在functions.php文件)
function registerAccount() {
if (isset($_REQUEST)) {
$username = $_REQUEST['username'];
$password = $_REQUEST['password]';
$email = $_REQUEST['email'];
$user_id = wp_create_user($username, $password, $email);
if (is_int($user_id)) {
$wp_user_object = new WP_User($user_id);
}
}
die();
}
add_action('wp_ajax_registerAccount', 'registerAccount');
的問題是我得到的錯誤功能的AJAX請求。這兩個文件都在同一個目錄中,你有什麼線索可以在這段代碼中損壞嗎?
隨着薩加爾的幫助,我設法使其工作,所以它不再運行錯誤功能,現在它調用成功功能,但wordpress帳戶不創建,請幫助我。
你不能要求你的functions.php直接 您必須使用的可溼性粉劑管理員的Ajax方法 –