Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

CodeIgniter form dropdown Validation?

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 */

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments