Skip to content

CodeIgniter form dropdown Validation?

Last updated on January 17, 2018

This post is about CodeIgniter Dropdown Menu(all so know as a select box) validation.See the below code samples for better understanding.

Create View : application/views/welcome_message.php

$options = array('-1' => 'SELECT SHIRT', 'small' => 'Small Shirt', 'med' =>
    'Medium Shirt', 'large' => 'Large Shirt', 'xlarge' => 'Extra Large Shirt', );
echo form_open('welcome/index');
echo form_error('shirts');
echo form_dropdown('shirts', $options);
echo form_submit('submit', 'submit');
echo form_close();

Create Controler file : appliction/controllers/welcome.php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Welcome extends CI_Controller
    public function index()
        $this->form_validation->set_rules('shirts', 'shirts', 'required|alpha_numeric');
            'You need to select something other than the default');
        if ($this->form_validation->run() == false) {
        } else {
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
0 0 votes
Article Rating
Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments