2012-04-11 2 views
0

양식이 클라이언트 측에서 유효성을 검사하지만 서버 측에서 유효성을 검사하지 않는 이유를 알아 내려고하고 있습니다. 내 PHP 완료하지만 그 심지어 내 요청을 서버에 양식을 제출 말하는 내 콘솔에 데려 오지 않아.양식을 제출하지 않습니다.

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

편집 :

나뿐만 아니라하지만 궁금이 jQuery를 사용하는 다른 형태를 가지고 누구든지 새로운 아이디어가 있습니까?

+0

당신이'.complete()'와'에는 .error를 (추가하려고했던 : 더이 시합을 읽고 싶은 사람들을 위해


이 내가에 대해 이야기하고있는 것입니다 '$ .ajax' 요청? 그들이 무엇을 반환합니까? –

답변

0

나는이 문제에 대한 답 ... 알고 나는이 하나 :))

CodeIgniter의이 POST 요청과 함께 아주 특별한 방식으로 작동을 도와 드리겠습니다 있도록 나에게 견과를 몰았다. 이 작업을 수행하는 대신 GET 요청을 사용하면 정상적으로 작동하는 것을 볼 수 있습니다 ... 그래서 무슨 일이 벌어 지나요?

Codeigniter에는 안전한 방식으로 데이터를 POST하기위한 crsf 토큰이 있습니다. 나머지 데이터와 함께이 crsf 값을 보내야합니다. 당신이 볼 수 있듯이

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

...

, 당신의 crsf 값은 쿠키에 저장됩니다

내가 당신에게 예를 줄 것이다,이 같은 내 POST 아약스 + CodeIgniter를 보이는 것입니다. jquery 플러그인 쿠키 도우미를 사용하지만 다른 플러그인을 사용하려고 시도합니다.

이 좋은 하루 되세요 POST 요청을 할 때

그러나, 는 CodeIgniter의에 의해 이름이 'csrf_test_name이'항상 예상되는 것을 명심! `핸들러) http://aymsystems.com/ajax-csrf-protection-codeigniter-20

+0

내가 이상한 방식으로 잘 작동하는 다른 형식을 가지고 있기 때문에 이상하지만이 양식을 사용하면 올바르게 작동하지 않습니다. –

+0

설정 파일에서 global_xss_filtering이 true로 설정되어 있습니까? –

+0

예 true로 설정됩니다. –

관련 문제