2012-04-11 11 views
0

私のフォームはクライアント側で検証されますが、サーバー側で検証しない理由を理解しようとしています。私は自分の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 
    { 

    } 
} 

ビュー:

<?php $attributes = array('class' => 'validate', 'id' => 'newArticleForm'); ?> 
      <?php echo form_open_multipart('', $attributes) ?> 
       <div class="content no-padding"> 
        <div class="section _100"> 
         <?php echo form_label('Title', 'title'); ?> 

         <div> 
          <?php echo form_input('title', '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Category', 'category'); ?> 

         <div> 
          <?php echo form_dropdown('category', $categories, '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Is Sticky', 'sticky'); ?> 

         <div> 
          <?php 
                  $options = array(
                     '' => 'Please Select An Option', 
                     '0' => 'No', 
                     '1' => 'Yes', 
                    ); 
                  ?><?php echo form_dropdown('sticky', $options, '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Allow Comments', 'comments'); ?> 

         <div> 
          <?php 
                  $options = array(
                     '' => 'Please Select An Option', 
                     '0' => 'No', 
                     '1' => 'Yes', 
                    ); 
                  ?><?php echo form_dropdown('comments', $options, '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Date Comments Expire', 'datetime'); ?> 

         <div> 
          <input id="datetime" type="datetime" class="required" /> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Status', 'status'); ?> 

         <div> 
          <?php 
                  $options = array(
                     '' => 'Please Select An Option', 
                     '0' => 'Inactive', 
                     '1' => 'Active', 
                    ); 
                  ?><?php echo form_dropdown('status', $options, '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Image', 'file'); ?> 
         <div> 
          <?php echo form_upload('file', '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Permalink', 'permalink'); ?> 

         <div> 
          <?php echo form_input('permalink', '', 'class="required"'); ?> 
         </div> 
        </div> 

        <div class="section _100"> 
         <?php echo form_label('Article', 'article'); ?><?php $attributes = array('name' => 'article', 'cols' => '30', 'rows' => '5', 'id' => 'article', 'class' => 'required') ?> 

         <div> 
          <?php echo form_textarea($attributes); ?> 
         </div> 
        </div> 
       </div><!-- End of .content --> 

       <div class="actions"> 
        <div class="actions-left"> 
         <?php echo form_reset(array('id' => 'reset', 'name' => 'reset'), 'Reset'); ?> 
        </div> 

        <div class="actions-right"> 
         <?php echo form_submit(array('id' => 'submit', 'name' => 'submit'), 'Submit'); ?> 
        </div> 
       </div><!-- End of .actions --> 
      <?php echo form_close(); ?> 

EDIT:

私もこのjqueryのを使用する他の形態を持っていますが、あれば不思議誰もが新しいアイデア?

+0

あなたは' .complete() 'と' .ERRORを(追加してみました:もっとこの試合を読みたい人のために


が、これは私が何を言っているかであります'$ .ajax'リクエスト?彼らは何を返しますか? –

答えて

0

ので、私はこの1つ:)であなたを助けて幸せです私は...この問題への答えを知っているし、それはナット私を運転した)

CodeIgniterのは、POSTリクエストで非常に特別な方法で動作します。これを行うが、代わりにGETリクエストを使用すると、正常に動作することがわかります...何が起こっているのですか?

Codeigniterにはcrsfトークンがあり、データを安全にPOSTすることができます。 このcrsf値を残りのデータとともに送信してください。

私はこれが私のPOSTアヤックス+ CodeIgniterのは、次のようになります、あなたの例を与える:

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

...

あなたが見ることができるように、あなたのcrsf値はクッキーに保存されています。私はjqueryプラグインのcookieヘルパーを使用しますが、他のプラグインを使用するように揚げています。

が素敵な一日をPOSTリクエストを作るとき

しかし、はCodeIgniterのことで名「csrf_test_name」が常に期待されていることに注意してください! `ハンドラに) http://aymsystems.com/ajax-csrf-protection-codeigniter-20

+0

私は他の形式を使用しているので、私は上の方法でうまく動作しますが、この形式では何らかの理由で正しく動作しません。 –

+0

設定ファイルで、global_xss_filteringがtrueに設定されていますか? –

+0

はいそれはtrueに設定されています –

関連する問題