I am learning codeigniter
when i create rule for validate dropdown box but its not given me error message

View File

    $option = array('0' =>'[ Please select an Experience Level ]',
            '1' => 'Without experience',
            '2' => 'Internship',
            '3' => 'Less than one year',
            '4' => 'One year',
            '5' => 'Two years',);

        $shirts_on_sale = array('small','0');
    echo form_dropdown('RequiredEducationLevel',$option,'0');
<?php echo form_error('RequiredEducationLevel','<span style="color:red;float:none;">','</span>');?>

Controller File

class Employee_Cont extends CI_Controller {

    public function __construct(){

public function register()

    $this->form_validation->set_rules('RequiredEducationLevel','Required Education Level','required|callback_check_default');
    $this->form_validation->set_message('check_default', 'You need to select something other than the default');

    if($this->form_validation->run() == FALSE)

    function check_default($post_string)
        return $post_string == '0' ? false : true;



Can you suggestion me what is actual problem.

Thank You

Edited by ravi142: add some code

3 Years
Discussion Span
Last Post by iamthwee

view file

<!-- use form open and point url to controller -->
<?php echo form_open('agency/form_validate'); ?>

<li id="AgencyType" style="z-index: 93;">
        <label class="mandatory" for="ExternalAgency">Are you an employment agency?</label>

            <li style="z-index: 92;">
                    $data = array(
                    echo form_radio($data);?>

                <label for="ExternalAgency">No, we recruit directly.</label>

            <li style="z-index: 91;">
                    $data = array('value'=>'HeadhuntingAgency',
                    echo form_radio($data); ?>

                <label for="HeadhuntingAgency">Yes, we are a headhunting/recruitment agency.</label>

            <li style="z-index: 90;">

                <?php $data = array('value'=>'TemporaryAgency',
                echo form_radio($data); ?>

                <label for="TemporaryAgency">Yes, we are a temporary staffing agency.</label>

            <?php echo form_error('ExternalAgency','<span style="color:red;float:none;">','</span>'); ?>


    <!-- make sure to have a button submit and close form -->
    <?php echo form_submit('ok', 'ok'); ?>
    <?php echo form_close(); ?>


public function form_validate()

        echo $this->input->post('ExternalAgency');

        $this->form_validation->set_rules('ExternalAgency', 'Agency', 'required');

        //if input is incorrect
        if ($this->form_validation->run() == FALSE)
            echo validation_errors();
            //input is good so do calculations

Edited by iamthwee


Important bits...

Make sure in your view to echo the path to the controller eg.

echo form_open('name_of_controller/form_validate');

I changed the radio array to include a value option as this is necessary.

I added a button and used a form_close.

It should be working now.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.