Php 不提交表格

Php 不提交表格,php,jquery,codeigniter,Php,Jquery,Codeigniter,我的表单将在客户端进行验证,但我正试图弄清楚为什么它不能在服务器端进行验证。我没有完整的php,但它甚至没有在我的控制台中打开POST请求,说它正在向服务器提交表单 jQuery: $(document).ready(function() { /* * Validate the form when it is submitted */ var validateform = $("#newArticleForm").validate({ invalidHandler: function(

我的表单将在客户端进行验证,但我正试图弄清楚为什么它不能在服务器端进行验证。我没有完整的php,但它甚至没有在我的控制台中打开POST请求,说它正在向服务器提交表单

jQuery:

$(document).ready(function()
{

/*
* Validate the form when it is submitted
*/
var validateform = $("#newArticleForm").validate({
    invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();
        if (errors) {
            var message = errors == 1
            ? 'You missed 1 field. It has been highlighted.'
            : 'You missed ' + errors + ' fields. They have been highlighted.';
            $('.box .content').removeAlertBoxes();
            $('.box .content').alertBox(message, {type: 'warning', icon: true, noMargin: false});
            $('.box .content .alert').css({
                width: '100%',
                margin: '0',
                borderLeft: 'none',
                borderRight: 'none',
                borderRadius: 0
            });
        } else {
            $('.box .content').removeAlertBoxes();
        }
    },
    showErrors : function(errorMap, errorList) {
        this.defaultShowErrors();
        var self = this;
        $.each(errorList, function() {
            var $input = $(this.element);
            var $label = $input.parent().find('label.error').hide();
            $label.addClass('red');
            $label.css('width', '');
            $input.trigger('labeled');
            $label.fadeIn();
        });
    },
    submitHandler: function(form) {
        var dataString = $('#newArticleForm').serialize();
        $.ajax({
            type: 'POST',
            url: '/kowmanager/dashboard/articleSubmit',
            data: dataString,
            dataType: 'json',
            success:  function(data) {
                if (data.error) {
                    $('.box .content').removeAlertBoxes();
                    $('.box .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false});
                    $('.box .content .alert').css({
                        width: '',
                        margin: '0',
                        borderLeft: 'none',
                        borderRight: 'none',
                        borderRadius: 0
                    });
                }
                else
                {
                    $('.box .content').removeAlertBoxes();
                    $('.box .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false});
                    $('.box .content .alert').css({
                        width: '',
                        margin: '0',
                        borderLeft: 'none',
                        borderRight: 'none',
                        borderRadius: 0
                    }); 
                    $(':input','#newArticleForm')
                    .not(':submit, :button, :hidden, :reset')
                    .val('');  
                }
            }
        });
    }
});

});
控制器:

function articleSubmit()
{
    $outputArray = array('error' => 'yes', 'message' => 'unproccessed');
    $outputMsg = '';
    // Sets validation rules for the login form
    $this->form_validation->set_rules('title', 'Title',
        'trim|required|xss_clean|alpha_numeric');
    $this->form_validation->set_rules('category', 'Category',
        'integer');
    $this->form_validation->set_rules('isSticky', 'Is Sticky',
        'integer');
    $this->form_validation->set_rules('comments', 'Allow Comments',
        'integer');    

    // Checks to see if login form was submitted properly
    if (!$this->form_validation->run())
    {
        $outputArray['message'] =
            'There was a problem submitting the form! Please refresh the window and try again!';
    }
    else
    {

    }
}
视图:

编辑:


我还有其他表单也使用这个jquery,但不知道是否有人有其他想法?

我知道这个问题的答案。。。这让我发疯,所以我很乐意帮你做这件事:

Codeigniter以一种非常特殊的方式处理POST请求。如果您这样做,但使用GET请求,您将看到它工作正常。。。发生了什么事

Codeigniter有一个crsf令牌,确保您以安全的方式发布数据。 因此,请确保将此crsf值与其他数据一起发送

我将给你一个例子,这就是我的POST ajax+codeigniter的样子:

$.ajax({
        type: 'POST',
        dataType: 'HTML',
        data: {
            somevalue : somevalue,
            csrf_test_name  : $.cookie('csrf_cookie_name')
        },

如您所见,您的crsf值存储在cookie中。我使用jquery插件cookie助手,但我觉得使用任何其他插件都很困难

但是,请记住,在发出POST请求时,codeigniter始终希望使用名称“csrf_test_name”

祝你今天愉快

对于那些想更多了解这一点的人,我想说的是:

是否尝试将.complete和.error处理程序添加到$.ajax请求中?它们会返回什么?奇怪的是,我使用的其他表单与上面的表单一样工作正常,但由于某些原因,此表单无法正常工作。在您的配置文件中,您的全局搜索过滤设置为true吗?那么我相信csrf_test_名称是必要的,虽然我不明白在没有csrf_test_name值:SWell的情况下如何使用POST方法发送其他表单,但如果我是你,我会尝试将当前的AJAX类型从POST更改为jquery和控制器代码中的AJAX类型。如果它与GET一起工作,那么您肯定知道它是crsf,如果它不工作,我建议查看链接,可能使用HTML helper中的相对链接站点\u url
$.ajax({
        type: 'POST',
        dataType: 'HTML',
        data: {
            somevalue : somevalue,
            csrf_test_name  : $.cookie('csrf_cookie_name')
        },