Php Post请求wordpress未索引
我有一个短代码(表格)要提交。我正在尝试使用JQuery提交它,并且在数据库中输入的值是未定义的。有人能帮我找到为什么我的$u POST请求结果为0吗 过程如下: submit.phpPhp Post请求wordpress未索引,php,jquery,wordpress,Php,Jquery,Wordpress,我有一个短代码(表格)要提交。我正在尝试使用JQuery提交它,并且在数据库中输入的值是未定义的。有人能帮我找到为什么我的$u POST请求结果为0吗 过程如下: submit.php $county = sanitize_text_field($_POST['county']); $country = sanitize_text_field($_POST['country']); $town = saniti
$county = sanitize_text_field($_POST['county']);
$country = sanitize_text_field($_POST['country']);
$town = sanitize_text_field($_POST['town']);
$postcode = sanitize_text_field($_POST['postcode']);
$property_description = sanitize_text_field($_POST['property_description']);
$displayable_address = sanitize_text_field($_POST['displayable_address']);
$nr_of_bedrooms = sanitize_text_field($_POST['nr_of_bedrooms']);
$nr_of_bathrooms = sanitize_text_field($_POST['nr_of_bathrooms']);
$price = sanitize_text_field($_POST['price']);
$property_type = sanitize_text_field($_POST['property_type']);
$sale_rent = sanitize_text_field($_POST['sale_rent']);
$custom = true;
$data_array = [
'county' => $county,
'country' => $country,
'town' => $town,
'postcode' => $postcode,
'property_description' => $property_description,
'displayable_address' => $displayable_address,
'nr_of_bedrooms' => $nr_of_bedrooms,
'nr_of_bathrooms' => $nr_of_bathrooms,
'price' => $price,
'property_type' => $property_type,
'sale_rent' => $sale_rent,
'custom' => $custom,
];
$wpdb->insert($wpdb->prefix . 'property', $data_array, $format=NULL);
这是我的JQuery:
$("#add-form").on("submit", function (e) {
e.preventDefault();
$(this).hide();
$("#property-status").html('<div class="alert alert-info text-center">Please wait!</div>');
var form = {
action: "r_submit_user_property",
county: $("#county").val,
country: $("#country").val,
town: $("#town").val,
postcode: $("#postcode").val,
property_description: $("#property_description").val,
displayable_address: $("#displayable_address").val,
nr_of_bedrooms: $("#nr_of_bedrooms").val,
nr_of_bathrooms: $("#nr_of_bathrooms").val,
price: $("#price").val,
property_type: $("#property_type").val,
sale_rent: $("#sale_rent").val
};
$.post(recipe_obj.ajax_url, form).always(function (response) {
if (response.status == 2) {
$('#property-status').html('<div class="alert alert-success">Property submitted successfully!</div>');
} else {
$('#property-status').html(
'<div class="alert alert-danger">Unable to submit property. Please fill in all fields.</div>'
);
$("#add-form").show();
$(“#添加表单”)。关于(“提交”,函数(e){
e、 预防默认值();
$(this.hide();
$(“#属性状态”).html('请稍候!');
变量形式={
操作:“r\u提交用户属性”,
县:$(“#县”).val,
国家:$(“#国家”).val,
城镇:$(“#城镇”).val,
邮政编码:$(“#邮政编码”).val,
物业描述:$(“#物业描述”).val,
可显示地址:$(“#可显示地址”).val,
卧室数量:$(“卧室数量”).val,
浴室数量:$(“浴室数量”).val,
价格:$(“#价格”).val,
属性类型:$(“#属性类型”).val,
销售租金:$(“销售租金”).val
};
$.post(recipe\u obj.ajax\u url,form).always(函数(响应){
如果(response.status==2){
$(“#属性状态”).html('property submitted successfully!');
}否则{
$(“#属性状态”).html(
“无法提交属性。请填写所有字段。”
);
$(“#添加表单”).show();
请将$(“#县”).val
更改为$(“#县”).val()
,因为val
是一个函数val()
var form = {
action: "r_submit_user_property",
county: $("#county").val(),
country: $("#country").val(),
town: $("#town").val(),
postcode: $("#postcode").val(),
property_description: $("#property_description").val(),
displayable_address: $("#displayable_address").val(),
nr_of_bedrooms: $("#nr_of_bedrooms").val(),
nr_of_bathrooms: $("#nr_of_bathrooms").val(),
price: $("#price").val(),
property_type: $("#property_type").val(),
sale_rent: $("#sale_rent").val()
};
另外,您应该检查
submit.php
文件中的参数值。我的错,不,我看到了:Dnow它不会提交,它直接转到jqueryspect元素中的else语句,并检查代码中是否存在语法错误。