2012-04-21 5 views
0

Я пытаюсь понять, почему функция запуска проверки формы возвращает false. В соответствии с документами сказано следующее:Не возвращать правильные правила проверки формы

Функция run() возвращает TRUE только в том случае, если она успешно применила ваши правила без каких-либо сбоев.

Вот что мои правила выглядеть следующим образом:

$this->form_validation->set_rules('nicknames', 'Nicknames', 
     'required'); 
    $this->form_validation->set_rules('hometown', 'Hometown', 
     'required'); 
    $this->form_validation->set_rules('height', 'Height', 
     'required'); 
    $this->form_validation->set_rules('Weight', 'Weight', 
     'required'); 
    $this->form_validation->set_rules('manager', 'Manager', 
     'required|integer'); 
    $this->form_validation->set_rules('setup', 'Setup', 
     'required'); 
    $this->form_validation->set_rules('finisher', 'Finisher', 
     'required'); 
    $this->form_validation->set_rules('biography', 'Biography', 
     'required'); 

Вот что проходит представление пост:

biography Kid coming out of college getting the chance of a lifetime. 
finisher Idolizer 
height 5'4" 
hometown Las Vegas, Nevada 
manager 0 
nicknames "The Quintessential Cruiserweight of KOW!"; "K-Dub" 
setup That's Wondeful 
submit Submit 
weight 140 lbs. 

http://pastebin.com/F9XeEibf 

function biographySubmit() 
{ 
    $outputArray = array('error' => 'yes', 'message' => 'unproccessed'); 
    $outputMsg = ''; 
    // Sets validation rules for the login form 
    $this->form_validation->set_rules('nicknames', 'Nicknames', 
     'required'); 
    $this->form_validation->set_rules('hometown', 'Hometown', 
     'required'); 
    $this->form_validation->set_rules('height', 'Height', 
     'required'); 
    $this->form_validation->set_rules('Weight', 'Weight', 
     'required'); 
    $this->form_validation->set_rules('manager', 'Manager', 
     'required|integer'); 
    $this->form_validation->set_rules('setup', 'Setup', 
     'required'); 
    $this->form_validation->set_rules('finisher', 'Finisher', 
     'required'); 
    $this->form_validation->set_rules('biography', 'Biography', 
     'required'); 

    // 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 
    { 
     $bioFields = array($this->input->post('nicknames'), $this->input->post('hometown'), $this->input->post('height'), $this->input->post('weight'), $this->input->post('manager'), $this->input->post('setup'), $this->input->post('finisher'), $this->input->post('biography'));   
     if ($this->bios->updateBiography($bioFields, $this->session->userdata('defaultRosterListID'))) 
     { 
      $outputArray = array('success' => 'Yes', 'message' => 
             'Biography were updated successfully!'); 
     } 
     else 
     { 
      $outputArray['message'] = 
      'The biopgraphy was not able to be updated in the database. Please try again later!'; 
     } 
    } 
    echo json_encode($outputArray); 
} 

JQuery Код:

var validateform = $("#biographyForm").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 #biographyForm .content').removeAlertBoxes(); 
      $('.box #biographyForm .content').alertBox(message, {type: 'warning', icon: true, noMargin: false}); 
      $('.box #biographyForm .content .alert').css({ 
       margin: '0', 
       borderLeft: 'none', 
       borderRight: 'none', 
       borderRadius: 0 
      }).delay(3000).fadeOut('slow'); 
     } else { 
      $('.box #biographyForm .content').removeAlertBoxes(); 
     } 
    }, 
    ignore : 'input:hidden:not(:checkbox):not(:radio)', 
    showErrors : function(errorMap, errorList) { 
        this.defaultShowErrors(); 
        var self = this; 
        $.each(errorList, function() { 
         var $input = $(this.element); 
         var $label = $input.parent().find('label.error').hide(); 
         if (!$label.length) { 
          $label = $input.parent().parent().find('label.error'); 
         } 
         if($input.is(':not(:checkbox):not(:radio):not(select):not([type=file])')) { 
          $label.addClass('red'); 
          $label.css('width', ''); 
          $input.trigger('labeled'); 
         } 
         $label.fadeIn(); 
        }); 
       }, 
    errorPlacement : function(error, element) { 
        if(element.is(':not(:checkbox):not(:radio):not(select):not([type=file])')) { 
         error.insertAfter(element); 
        } else if(element.is('select')) { 
         error.appendTo(element.parent()); 
        } else if (element.is('[type=file]')){ 
         error.insertAfter(element.parent()); 
        } else { 
         error.appendTo(element.parent().parent()); 
        } 

        if ($.browser.msie) { 
         error.wrap('<div class="error-wrap" />'); 
        } 
       }, 
    submitHandler: function(form) { 
     var dataString = $('#biographyForm').serialize(); 
     $.ajax({ 
      type: 'POST', 
      url: 'biography/biographySubmit', 
      data: dataString, 
      dataType: 'json', 
      success: function(data) { 
       if (data.error) { 
        $('.box #biographyForm .content').removeAlertBoxes(); 
        $('.box #biographyForm .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false}); 
        $('.box #biographyForm .content .alert').css({ 
         width: '', 
         margin: '0', 
         borderLeft: 'none', 
         borderRight: 'none', 
         borderRadius: 0 
        }).delay(3000).fadeOut('slow'); 
       } 
       else 
       { 
        $('.box #biographyForm .content').removeAlertBoxes(); 
        $('.box #biographyForm .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false}); 
        $('.box #biographyForm .content .alert').css({ 
         width: '', 
         margin: '0', 
         borderLeft: 'none', 
         borderRight: 'none', 
         borderRadius: 0 
        }).delay(3000).fadeOut('slow'); 
       } 
      } 
     }); 
    } 
}); 
+0

Возможно, вам будет полезна соответствующий HTML-код формы. –

+0

Трудно сказать .. просто угадайте попытку ввести высоту без единой цитаты, напишите 5.4 вместо 5'4 – Melsi

+0

Я обновил свой пост с помощью html-формы –

ответ

1

Я не уверен, если это полностью устранит вашу проблему, но ваша форма не кажется hav e a action. Это должно быть что-то вроде action="[your site url]/your_controller_name/biographySubmit".

Вы можете использовать CodeIgniter в URL Helper и использовать это: action="<?php echo site_url("your_controller_name/biographySubmit"); ?>"

Без действия, данные в форме, не будут переданы biographySubmit функции в контроллере.

+0

Это не потому, что я проверяю форму с помощью jquery и использую функцию ahe ajax для отправки на php. –

+0

@ user1333299 Не могли бы вы разместить соответствующий код jQuery и ajax? Знаете ли вы, какие проверки (проверки) проверки не выполняются? Если вы поместите это в свое мнение: ' 'он покажет, какие проверки не передаются, когда вы отправляете. – jleft

+0

Я отправил код jquery. –

Смежные вопросы