How to create form in CodeIgniter




For working with form in CodeIginter you have to use form helper.

Load the form helper

You can also load the form helper in application/config/autoload.php.

Benefit of loading from  helper in the autoload.php is that if you have multiple form then you have to use form helper in every controller but loading form helper in autoload.php  then no need to load form helper in every controller. It will automatically autoload in every controller.

How to start a from

$action (string) : Main controller

$attributes (array) : HTML attributes like name, class etc.

For ex :

This will produce

How to create input text field 

This will produce

How to create password text field 

This will produce

How to create drop down list

name : name of the drop down list

$options : list of the dropdowns

$selectedvalues :  If you wish to be selected a value

Ex for dropdwon list : 



This will produce like

If you wish to a selected one value

This will produce this

If you wish to selected multiple value

This will produce this

How to create radio button

$data (array) : Field  data

$values (string) : Field  value

$checked : whether this radio button being checked

$extras :  Extra attributes

Ex :

This will produce this

How to create checkbox

$data (array) : Field  data

$values (string) : Field  value

$checked : whether this check box being checked

$extras :  Extra attributes

Ex :

This will produce this

How to create textarea

This will produce this

How to create submit button

This will produce this

How to create resetbutton

This will produce this

How to close a form

form_close function used to close form.

Full Form scripts

First load form helper in application/config/autoload.php.

then create a controller (Signupform.php)

Now to form view(signup_form.php)