警告:strtolower()希望参数1在wordpress中是字符串

时间:2015-12-16 05:03:07

标签: php jquery ajax wordpress

我在wordpress中使用ajax开发了一个表单。它在localhost中正常工作但是当我在实时服务器上传代码时,它给我提交表单时出错。错误是: 警告:strtolower()期望参数1为字符串,数组在第1426行的/home/content/26/11637326/html/surakshadal/wp-includes/formatting.php中给出

查看我的代码: 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');

1 个答案:

答案 0 :(得分:2)

在您的代码中,我没有发现任何问题,但在comment_status $my_post您传递的数组中,请尝试从[] 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
 );