2010-07-05 4 views
2

Привет там У меня возникли проблемы с моей проверки формы, в основном проблема заключается в том, что я получаю повторное представление загруженную если проверка не пройдена, пожалуйста, см мой фрагмент кода,Codeigniter form_validation помощь

else { 
      //the user is a new customer so we need to show them 
      //the card details form 
      $this->addViewData('returningCustomer', false); 
      $this->load->library('form_validation'); 
      if($this->input->post('carddetails') == 'Submit') { 
       $this->form_validation->set_rules('inpcardtype', 'Card type', 'cardTypeCheck'); //custom callback 
       $this->form_validation->set_rules('inpcardnumber', 'Card number', 'required|trim|exact_length[16]'); 
       $this->form_validation->set_rules('startmonth', 'Start month', 'trim|required'); 
       $this->form_validation->set_rules('startyear', 'Start year', 'trim|required'); 
       $this->form_validation->set_rules('endmonth', 'End month', 'trim|required'); 
       $this->form_validation->set_rules('endyear', 'End year', 'trim|required'); 
       $this->form_validation->set_rules('inpissuenumber', 'Issue number', 'trim|integer'); 
       $this->form_validation->set_rules('inpccv', 'CCV Code', 'required|trim|exact_lenght[3]'); 
       if($this->form_validation->run() == FALSE) { 
        $this->renderTemplate('cv/search/pf_shortlist.php', $this->viewData); 
       } else { 
        // validation is passed we need to safe the user details 
        // it is probable that we will need to hash the users card details 
        //@TODO: HASH USER CARD DETAILS LEAVE ONLY THE FINAL DIGITS 
        $this->load->model('checkout_model'); 
       } 
      } 
      $this->renderTemplate('cv/search/pf_shortlist.php', $this->viewData); 

в основном, если condtion не работает по сценарию, представление загружается формой, форма отправляется, и если проверка не выполняется, пользователь возвращается к форме, но показывает ошибки, однако исходный вид также присутствует. Могу ли я остановить это?

ответ

1

После

$this->renderTemplate('cv/search/pf_shortlist.php', $this->viewData);

Вы должны сделать return;, как после утверждения еще Theres другой вид нагрузки. #

 //the user is a new customer so we need to show them 
     //the card details form 
     $this->addViewData('returningCustomer', false); 
     $this->load->library('form_validation'); 
     if($this->input->post('carddetails') == 'Submit') { 
      $this->form_validation->set_rules('inpcardtype', 'Card type', 'cardTypeCheck'); //custom callback 
      $this->form_validation->set_rules('inpcardnumber', 'Card number', 'required|trim|exact_length[16]'); 
      $this->form_validation->set_rules('startmonth', 'Start month', 'trim|required'); 
      $this->form_validation->set_rules('startyear', 'Start year', 'trim|required'); 
      $this->form_validation->set_rules('endmonth', 'End month', 'trim|required'); 
      $this->form_validation->set_rules('endyear', 'End year', 'trim|required'); 
      $this->form_validation->set_rules('inpissuenumber', 'Issue number', 'trim|integer'); 
      $this->form_validation->set_rules('inpccv', 'CCV Code', 'required|trim|exact_lenght[3]'); 
      if($this->form_validation->run() == FALSE) { 
       $this->renderTemplate('cv/search/pf_shortlist.php', $this->viewData); 
       return;// HERE 
      } else { 
       // validation is passed we need to safe the user details 
       // it is probable that we will need to hash the users card details 
       //@TODO: HASH USER CARD DETAILS LEAVE ONLY THE FINAL DIGITS 
       $this->load->model('checkout_model'); 
      } 
     } 
     $this->renderTemplate('cv/search/pf_shortlist.php', $this->viewData); 
     return; 
Смежные вопросы