2015-12-16 46 views
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'); 

回答

2

在你的代码,我看不出有什么问题,但在你的你逝去的阵列,尽量去除$my_postcomment_status[] from open

$my_post = array(
    'post_title' => $title, 
    'post_content' => $rev, 
    'post_status' => 'publish', 
    'post_type'  => 'reviews', 
    'comment_status' => 'open' ,//[ 'open' ], this is the array which may creates error 
); 
+1

It works。Thanks a lottt Rohan :) –

相关问题