Posts

Showing posts with the label Codeigniter Form Helper

Codeigniter - Date Format - Form Validation

Answer : You can take use of CodeIgniters callback functions by creating a callback_date_valid() function that check if the date is valid. And to check if it is valid, you could use PHP's checkdate function array( 'field' => 'reg[dob]', 'label' => 'DOB', 'rules' => 'required|date_valid' ) function callback_date_valid($date){ $day = (int) substr($date, 0, 2); $month = (int) substr($date, 3, 2); $year = (int) substr($date, 6, 4); return checkdate($month, $day, $year); } I have a pretty clean solution for this. You can extend codeigniters form validation library. Do this by putting a MY_Form_validation.php file in your application/libraries folder. This file should look like this: class MY_Form_validation extends CI_Form_validation { public function __construct($rules = array()) { parent::__construct($rules); } public function valid_date($date) { $d = DateTime:...