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

Member Avatar for iamthwee

Will post up a full example in a bit.

Member Avatar for 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
Member Avatar for 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.