【问题标题】:Warning: strtolower() expects parameter 1 to be string in wordpress警告:strtolower() 期望参数 1 是 wordpress 中的字符串
【发布时间】:2015-12-16 05:03:07
【问题描述】:

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

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

【问题讨论】:

    标签: php jquery ajax wordpress


    【解决方案1】:

    在您的代码中我没有看到任何问题,但在您的 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
     );
    

    【讨论】:

      猜你喜欢
      • 2023-01-17
      • 2017-05-10
      • 2016-11-26
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      相关资源
      最近更新 更多