Codeigniter 4 – Form Helper with Examples
Form Helpers
- Form Helpers are a set of functions that assist with creating and managing forms.
- Form Helpers are stored in the system/Helpers/Form_helper.php file.
Loading the Form Helper
- Use the helper() function to load the Form Helper.
Example:
helper('form');
Creating a Form
- Use the form_open() function to create a form.
Example:
echo form_open('controller/method');
Creating Form Elements
- Use the form_input() function to create a text input field.
Example:
echo form_input('name', 'value');
- Use the form_password() function to create a password input field.
Example:
echo form_password('password', 'value');
- Use the form_checkbox() function to create a checkbox.
Example:
echo form_checkbox('checkbox', 'value', true);
- Use the form_radio() function to create a radio button.
Example:
echo form_radio('radio', 'value', true);
- Use the form_dropdown() function to create a dropdown menu.
Example:
$options = array(
'option1' => 'Option 1',
'option2' => 'Option 2'
);
echo form_dropdown('dropdown', $options, 'option1');
Creating a Form Button
- Use the form_submit() function to create a submit button.
Example:
echo form_submit('submit', 'Submit');
Closing a Form
- Use the form_close() function to close a form.
Example:
echo form_close();
Setting Form Attributes
- Use the form_open() function with the second parameter to set form attributes.
Example:
echo form_open('controller/method', array('class' => 'form-horizontal'));
I hope this helps! Let me know if you have any further questions or need more information.