当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Warning: strtolower() expects parameter 1 to be string in wordpress

问题描述:

I have developed a form using ajax in wordpress .Its working fine in localhost but when i uploaded the code on live server it gives me error on submitting the form.The error is:

Warning: strtolower() expects parameter 1 to be string, array given in /home/content/26/11637326/html/surakshadal/wp-includes/formatting.php on line 1426

Have a look on my code :

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>

below is my jquery and ajax code:

 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);

}

});

});

and below is my php code in fucntions.php file:

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');

网友答案:

In your code I don't see any issue but in your comment_status of $my_post you are passing array so try to remove the [] 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
 );
分享给朋友:
您可能感兴趣的文章:
随机阅读: