Dpk_Gopi
Dpk_Gopi

Reputation: 267

form_dropdown() is not taking the "name" attribute in codeigniter

I am creating a form in codeigniter using form helper class.

But using 'form_dropdown("medium_type",$medium_type,"Select Medium")' is not taking the name attribute and hence form validations are not working after post.

Can anyone tell me how I can pass the name to the element.

function controller(){
  $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->data['medium_type']  = $this->field_enums('notifications', 'medium_type');
             $this->data['user_type'] = $this->field_enums('notifications', 'user_type');
                            $this->form_validation->set_rules('medium_type', 'Medium Type', 'required');

            if ($this->form_validation->run() == FALSE)
            {
                    $this->load->view('admin/notifications', $this->data);
            }
            else
            {
                    $data = array(
                    'title' => $this->input->post('title'),
                    'medium_type' => $this->input->post('mediun_type'),
                    );
                    $this->notifications_m->insert($data);

            }
            $this->load->view('admin/notifications', $this->data);
}

form code ` Title

                        <div class="input-field col s12 m6 l6 margin-bottom-10px">
                          <?php echo form_dropdown("medium_type",$medium_type);?>
                          <label for="medium_tyoe">Medium Type</label>
                          <?php echo form_error('medium_type'); ?>
                        </div>

                    <div class="input-field col s12 m12 l12 margin-bottom-10px">
                          <?php echo $this->ckeditor->editor("content");?>
                          <?php echo form_error('content'); ?>
                        </div>

                        <div class="btn waves-effect waves-light col s8 m4 l4 offset-m4 offset-l4 offset-s2 ">
                          <?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
                    <i class="material-icons right">send</i>
                        </div>
                      </div>
                    </div>
                <?php echo form_close();?>`

Upvotes: 1

Views: 670

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38642

In Form

$options = array(
        'option'         => 'Name',
        'option2'         => 'Name2',
);

echo form_dropdown('medium_type', $options, 'option2');
echo form_error('medium_type');  # to show error

In controller

$this->form_validation->set_rules('medium_type', 'Medium Type', 'required');

if ($this->form_validation->run() == FALSE)
{
    # load the form view
}
else
{
    # Validation  pass
    $medium_type = $this->input->post('medium_type');

    echo $medium_type ;
}

Upvotes: 1

Related Questions