2015-01-27 2 views
0

Привет я взял этот код у одного из StackOverflow CodeIgniter вопроса, и попытаться вписать его в моемCodeigniter: Дата ошибка проверки

контроллер:

public function index(){ 
     $data['months'] = array('FALSE' => 'Month', 
       '1' => 'Jan', 
       '2' => 'Feb', 
       '3' => 'Mar', 
       '4' => 'Apr', 
       '5' => 'May', 
       '6' => 'Jun', 
       '7' => 'Jul', 
       '8' => 'Aug', 
       '9' => 'Sep', 
       '10' => 'Oct', 
       '11' => 'Nov', 
       '12' => 'Dec' 
       ); 
     $data['days']['FALSE'] = 'Day';   
     for($i=1;$i<=31;$i++){ 
      $data['days'][$i] = $i; 
     } 

    $start_year = date("Y",mktime(0,0,0,date("m"),date("d"),date("Y")-100)); 
    $data['years']['FALSE'] = 'Year'; 

    for ($i=$start_year;$i<=date("Y");++$i) { 
     $data['years'][$i] = $i; 
    } 
    $this->load->view('signup', $data); 
} 

вид:

echo form_label('Select you birthday','birthday')."<br/>". 
     form_dropdown('days',$days). " " . form_dropdown('months',$months). " " . form_dropdown('years',$years); 

Контроллер:

public function signup_validation(){ 
     $this->load->library('form_validation'); 

     $this->form_validation->set_rules('salutation', 'Salutation', 'required'); 
     $this->form_validation->set_rules('fName', 'First Name', 'required|trim|alpha|xss_clean|strip_tags'); 
     $this->form_validation->set_rules('lName', 'Last Name', 'required|trim|alpha|xss_clean|strip_tags'); 
     if($this->form_validation->run()){ 
      $month = $this->input->post('months'); 
      $day = $this->input->post('days'); 
      $year = $this->input->post('years'); 
      $birthday = date("d-m-Y",mktime(0,0,0,$month,$day,$year)); 
     } 
     $this->form_validation->set_rules('address', 'Address', 'required|trim|xss_clean|strip_tags|alpha_numeric'); 
     $this->form_validation->set_rules('contact', 'Contact No', 'required|trim|xss_clean|strip_tags|numeric|min_length[8]|max_length[8]'); 
     $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|is_unique[users.email]|xss_clean|strip_tags'); 
     $this->form_validation->set_rules('username', 'Username', 'required|trim|alpha_numeric|xss_clean|strip_tags'); 
     $this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[8]|xss_clean|strip_tags|alpha_numeric'); 
     $this->form_validation->set_rules('cpassword', 'Confirm Password', 'required|trim|matches[password]|xss_clean|strip_tags|alpha_numeric'); 

     if ($this->form_validation->run()){ 
      $key = md5(uniqid()); 

      $this->load->library('email', array('mailtype'=>'html')); 
      $this->load->model('model_users'); 

      $this->email->from('[email protected]', "SWAP"); 
      $this->email->to($this->input->post('email')); 
      $this->email->subject("Confirm your account."); 

      $message = "<p>Thank you for signing up!</p>"; 
      $message .= "<p><a href='".base_url()."main/register_user/$key'>Click Here</a> to confirm your account</p>"; 

      $this->email->message($message); 

      if ($this->model_users->add_temp_users($key, $birthday)){ 
       if ($this->email->send()){ 
        echo "The email has been sent!"; 
       } else echo "Could not send the mail"; 
      } else echo "problem adding to database"; 

     } else { 
      $this->load->view('signup'); 
     } 
    } 

Все работает отлично, до тех пор, когда есть ошибка проверки этого будет отображаться: enter image description here

ответ

1

Если ошибка проверки означает просто присвоить пустые значения для месяца, дня и года ИЛИ Установленного значения для месяца, дня и года в в начале функции ... не загружать его внутри проверки ... проверить массив foreach с is_array() функция ...

+0

Большое вам спасибо! :) – Outliers

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