may i know how do i ensure that the user have selected, Dr, Mr, Ms, Mdm and when they submit the form if the salutation is given as blank it will return an error message for the set_rules().
Code:
echo "<p>Salutation: ";
$salutationOptions = array(
'' => '',
'Dr' => 'Dr',
'Mr' => 'Mr',
'Ms' => 'Ms',
'Mdm' => 'Mdm',
);
echo form_dropdown('salutation', $salutationOptions, '');
echo "</p>";
In the view file, you can do a client side validation using this:
echo "<p>Salutation: ";
$salutationOptions = array(
'' => '',
'Dr' => 'Dr',
'Mr' => 'Mr',
'Ms' => 'Ms',
'Mdm' => 'Mdm',
);
echo form_dropdown('salutation', $salutationOptions, '', 'required="required"');
echo "</p>";
When the user tries to submit without choosing form the dropdown, it will give them an error saying they should choose from the dropdown.
If you want it on the server side, you can do something like this:
$this->form_validation->set_rules('salutation', 'Salutation', 'required')
if($this->form_validation->run()){
/*user has selected. use the data now*/
}else{
/*user has not sleected data, throw error back*/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With