需要检查日期字段是否为空

时间:2015-07-07 08:45:40

标签: php codeigniter

我正在使用codeigniter。在我的控制器文件中,我需要获取雇员的雇用日期和终止日期,并检查雇用日期是否小于终止日期。 我的控制器代码如下:

 public function add()
{
    //if save button was clicked, get the data sent via post
    if ($this->input->server('REQUEST_METHOD') === 'POST')
    {

        //$this->load->library('session');
        //$this->session->unset_userdata('tax_details');
        //form validation
                    $this->form_validation->set_rules('id', 'id');

        $this->form_validation->set_rules('emp_first_name', 'emp_first_name','alpha');
        $this->form_validation->set_rules('emp_last_name', 'emp_last_name','alpha');
        $this->form_validation->set_rules('emp_email_id', 'emp_email_id');
        $this->form_validation->set_rules('emp_emergency_contact', 'emp_emergency_contact');
        $this->form_validation->set_rules('category', 'category');
        $this->form_validation->set_rules('emp_id_card', 'emp_id_card');
        $this->form_validation->set_rules('emp_time_in', 'emp_time_out');
        $this->form_validation->set_rules('emp_date_of_hire', 'emp_date_of_hire');
        $this->form_validation->set_rules('emp_date_of_termination', 'emp_date_of_termination');
        $this->form_validation->set_rules('emp_date_of_rehire', 'emp_date_of_rehire');
        $this->form_validation->set_rules('emp_reference_num', 'emp_reference_num');
        $this->form_validation->set_rules('emp_service_limitation', 'emp_service_limitation');
        $this->form_validation->set_rules('chair_renter', 'chair_renter');
        $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');

        //if the form has passed through the validation
        if ($this->form_validation->run())
        {
            $data_to_store = array(
                 'id' => $this->input->post('id'),
                'emp_first_name' => $this->input->post('emp_first_name'),
                'emp_last_name' => $this->input->post('emp_last_name'),
                'emp_email_id' => $this->input->post('emp_email_id'),
                'emp_emergency_contact' => $this->input->post('emp_emergency_contact'),          
                'category' => $this->input->post('category'),
                'emp_id_card' => $this->input->post('emp_id_card'),
                'emp_time_in' => $this->input->post('emp_time_in'),
                'emp_time_out' => $this->input->post('emp_time_out'),
                'emp_date_of_hire' => $this->input->post('emp_date_of_hire'),
                'emp_date_of_termination' => $this->input->post('emp_date_of_termination'),
                'emp_date_of_rehire' => $this->input->post('emp_date_of_rehire'),
                'emp_reference_num' => $this->input->post('emp_reference_num'),
                'emp_service_limitation' => $this->input->post('emp_service_limitation'),
                'chair_renter' => $this->input->post('chair_renter'),

            );
            if($data_to_store['emp_date_of_hire'] != NULL || $data_to_store['emp_date_of_termination'] != NULL || $data_to_store['emp_date_of_rehire'] != NULL)
            {
                $data_to_store['emp_date_of_hire'] = str_replace('/', '-', $data_to_store['emp_date_of_hire'] );
                $date1 = date("Y-m-d", strtotime($data_to_store['emp_date_of_hire']));
                $data_to_store['emp_date_of_termination'] = str_replace('/', '-', $data_to_store['emp_date_of_termination'] );
                $date2 = date("Y-m-d", strtotime($data_to_store['emp_date_of_termination']));  
                $data_to_store['emp_date_of_rehire'] = str_replace('/', '-', $data_to_store['emp_date_of_rehire'] );
                $date3 = date("Y-m-d", strtotime($data_to_store['emp_date_of_rehire']));  
                if($date1 < $date2 && $date1 < $date3)
                {
                 if($this->employee_model->store_employee($data_to_store)){
                $data['flash_message'] = TRUE; 
                $this->session->set_flashdata('flash_message', 'updated');
                //$this->session->set_userdata('tax_details', ['total'=>$this->input->post('id'),"tax"=>$this->input->post('emp_service_limitation'),"renter"=>$this->input->post('chair_renter')]);
               //redirect(base_url().'admin/employee/view');



               if($data_to_store['chair_renter'] == "yes")
            {
                $datas = array(
                'emp_id'=>$data_to_store['id'],
                'emp_first_name'=>$data_to_store['emp_first_name'],
                'emp_last_name'=>$data_to_store['emp_last_name'],
                'category'=>$data_to_store['category'],
                );
                $this->employee_model->save_chair_renter($datas);
            }

            }else{
                $data['flash_message'] = FALSE; 
            }   
                }
                else
                {
                 $data['flash_message'] = FALSE; 
                }

            //if the insert has returned true then we show the flash message
    }
    else
    {

     if($this->employee_model->store_employee($data_to_store)){
                $data['flash_message'] = TRUE; 
                $this->session->set_flashdata('flash_message', 'updated');
                //$this->session->set_userdata('tax_details', ['total'=>$this->input->post('id'),"tax"=>$this->input->post('emp_service_limitation'),"renter"=>$this->input->post('chair_renter')]);
               //redirect(base_url().'admin/employee/view');



               if($data_to_store['chair_renter'] == "yes")
            {
                $datas = array(
                'emp_id'=>$data_to_store['id'],
                'emp_first_name'=>$data_to_store['emp_first_name'],
                'emp_last_name'=>$data_to_store['emp_last_name'],
                'category'=>$data_to_store['category'],
                );
                $this->employee_model->save_chair_renter($datas);
            }

            }else{
                $data['flash_message'] = FALSE; 
            }   
    }


        }

    }
    //fetch manufactures data to populate the select field
    $data['designation'] = $this->designation_model->get_designation();
    //load the view
    $data['main_content'] = 'admin/employee/add';
    $this->load->view('includes/template', $data);  
}  

我需要检查日期字段是否为空。在我的视图文件中,我得到如下所示的输入。

      <input type="date" name="emp_date_of_hire" value="<?php echo set_value('emp_date_of_hire'); ?>">
  <input type="date" name="emp_date_of_termination" value="<?php echo set_value('emp_date_of_termination'); ?>">

如何编码?有人能帮助我吗?

0 个答案:

没有答案
相关问题