0
我已經開發了一個在wordpress中使用ajax的表單。它在localhost中正常工作,但是當我將代碼上傳到活動服務器時,它會給我提交表單時的錯誤。錯誤是: 警告:用strtolower()預計參數1是串,陣列中的給定/home/content/26/11637326/html/surakshadal/wp-includes/formatting.php在線路1426警告:strtolower()期望參數1是wordpress中的字符串
上看一看我的代碼: HTML:
<form class="form-horizontal" id="revForm" action=" " method="post">
<div class="formDetailsSections">
<div class="form-group formSubheading " id="formExDiv">
<p>Express Yourself</p>
</div><!-- account details-->
<div class="form-group ">
<label for="revArea" class="formText col-sm-4 control-label " style="text-align: center">Area</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="revArea" placeholder="Enter related Area">
</div>
</div>
<div class="form-group ">
<label for="revTitle" class="formText col-sm-4 control-label " style="text-align: center">Title</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="revTitle" placeholder="Enter Title">
</div>
</div>
<div class="form-group ">
<label for="reviewS" class="formText col-sm-4 control-label " style="text-align: center">Suggest/Complaint</label>
<div class="col-sm-7">
<textarea name="reviewS" class="form-control" id="reviewS" placeholder="Write For The Community"></textarea>
</div>
</div>
<div class="divError">
<p class="error"> </p>
</div>
</div>
<div class="formButton">
<button type="submit" id="revFormBtn" class="btn btn-warning btn-lg">Post</button>
</div>
</form>
下面
是我jQuery和Ajax代碼:
jQuery("#revForm").submit(function(e)
{
e.preventDefault();
var area=jQuery("#revArea").val();
var title=jQuery("#revTitle").val();
var rev=jQuery("#reviewS").val();
console.log(area);
console.log(title);
var ajaxdata={
action:'review_action',
area:area,
title:title,
rev:rev
};
jQuery.post(ajaxurl, ajaxdata,function(res)
{
if (res=='')
{
jQuery("#PostSubmittedDiv").show();
jQuery("#formSuggestDiv").hide();
}
else {
jQuery(".divError").html(res);
}
});
});
以下是fucntions.php文件我的PHP代碼:
function review()
{
if($_POST['action']=='review_action')
{
$area=$_POST['area'];
$title=$_POST['title'];
$rev=$_POST['rev'];
$my_post = array(
'post_title' => $title,
'post_content' => $rev,
'post_status' => 'publish',
'post_type' => 'reviews',
'comment_status' => [ 'open' ],
);
$post1= wp_insert_post($my_post);
if (is_wp_error($post1))
echo $post1->get_error_message();
}
wp_die();
}
add_action('wp_ajax_review_action', 'review');
add_action('wp_ajax_nopriv_review_action', 'review');
It works。Thanks a lottt Rohan :) –