Welcome Guest, Not a member yet? Register   Sign In
How to validate form dropdown in codeigniter
#1

Can I know, How  to validate form dropdown in codeigniter.

This is my View File


PHP Code:
<div class="form-group">
 
                           <label style="color: #E4BC3A; font-size: 18px">Choosing of the runnre</label>
 
                           <select class="form-control select2" style="width: 100%;" name="runner_id">
 
                               <option value="<?php echo $row2->runner_id ?>"><?php echo $row2->runner_name?></option>
                                <?php foreach ($supporter_data as $row3){
 
                                   ?>
                                    <option value="<?php echo $row3->runner_id ?>"><?php echo $row3->runner_name?></option>
                                    <?php
                                
?>
                            </select>
                        </div> 

This is controller
PHP Code:
   function index()
 
   {
 
       if ($this->input->post())
 
       {
 
           $this->form_validation->set_rules('runner_id''Runner's Name', 'required');
            
        }
        if ($this->form_validation->run() == TRUE)
        {
            $this->Supporter_model->movement_add();
            redirect('
supporter/index');

        }
        $data["supporter_data"] = $this->Supporter_model->runner_data();
        $data["movement_data"] = $this->Supporter_model->movement_list();

        $this->load->model("Requisition_model");
        $data["requisition"] = $this->Requisition_model->public_view();
        $data["requisition_done"] = $this->Requisition_model->public_view_job_done();
        //var_dump($data["requisition"]); die();
        $this->load->view('
supporter/public', $data);
    } 
Reply
#2

You use in_list

PHP Code:
  function index()
 
   {
        
/***
            Needs to reformed as:
            array(
                runner_id => runner_name
            )
            So that you can access them by $data["supporter_data"][runner_id] and get runner_name
            
            View need to be adapted too
        ***/
        
$data["supporter_data"] = $this->Supporter_model->runner_data();

        
        
$this->form_validation->set_rules('runner_id'"Runner's Name"'required|in_list['.implode(array_keys($data["supporter_data"]),',').']');

 
       if ($this->form_validation->run() === TRUE)
 
       {
 
           $this->Supporter_model->movement_add();
 
           redirect('supporter/index');
 
       }
        else
        {
            
$data["movement_data"] = $this->Supporter_model->movement_list();
            
            
$this->load->model("Requisition_model");
            
$data["requisition"] = $this->Requisition_model->public_view();
            
$data["requisition_done"] = $this->Requisition_model->public_view_job_done();
            
$this->load->view('supporter/public'$data);
        }
 
   
Reply
#3

(05-01-2018, 11:52 AM)jreklund Wrote: You use in_list

PHP Code:
  function index()
 
   {
        
/***
            Needs to reformed as:
            array(
                runner_id => runner_name
            )
            So that you can access them by $data["supporter_data"][runner_id] and get runner_name
            
            View need to be adapted too
        ***/
        
$data["supporter_data"] = $this->Supporter_model->runner_data();

        
        
$this->form_validation->set_rules('runner_id'"Runner's Name"'required|in_list['.implode(array_keys($data["supporter_data"]),',').']');

 
       if ($this->form_validation->run() === TRUE)
 
       {
 
           $this->Supporter_model->movement_add();
 
           redirect('supporter/index');
 
       }
        else
        {
            
$data["movement_data"] = $this->Supporter_model->movement_list();
            
            
$this->load->model("Requisition_model");
            
$data["requisition"] = $this->Requisition_model->public_view();
            
$data["requisition_done"] = $this->Requisition_model->public_view_job_done();
            
$this->load->view('supporter/public'$data);
        }
 
   


Can I know how should  I write view dropdown code. I have no idea about that.
Reply
#4

See the form_helper in the CodeIgniter User's Guide.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB