Skip to content Skip to sidebar Skip to footer

Dropdown Required Not Working In Codeigniter

I want to make the mail is field required, but somehow its not working, am i missing something?

Solution 1:

Noticed several issues in code. required & array spelling is wrong moreover wrong syntax used in last params in form_dropdown() function

Try this

<divclass="col-md-5 "><divclass="control-group form-group"><labelclass="control-label">
      Escalation Email Ids
    </label><divclass="controls"><?php$options=array(); if(count($useridsoptions)){ foreach($useridsoptionsas$key=>$val){ $options[$key]=$val; } } echo form_dropdown('esc_users[]', $options, explode(",",$row->esc_users),'id="esc_users" class="form-control function col-md-12 select2" required="required" multiple'); ?></div></div></div>

Solution 2:

Codeigniter dropdown validation example

<?phpecho form_label("Country:
","country");
     $data = array(
          "selectcountry"  => "Select Country",               
          "CA" => "Canada",
          "US" => "United States",
          "ZW" => "Zimbabwe"
                  );
     echo form_dropdown('country', $data, 'selectcountry');?>

form validation rule

<?php$this->form_validation->set_rules('country', 'Country', 'required|callback_country_check');?>

callback method

publicfunctioncountry_check()
    {
            if ($this->input->post('country') === 'selectcountry')  {
            $this->form_validation->set_message('country_check', 'Please choose your country.');
            returnFALSE;
        }
        else {
            returnTRUE;
        }
    }

Post a Comment for "Dropdown Required Not Working In Codeigniter"