Call back validation calling first then required validation is calling. I want to call required validation first.
My set_validation function code:
public function set_validation()
{
$this->form_validation->set_rules('from', 'Ended Date', 'required|callback_compareDates');
}
In order to alter the sequence of the execution you need modify the core library file in /system/libraries/Form_validation.php
From function
protected function _prepare_rules($rules)
{
...
...
return array_merge($callbacks, $new_rules);
}
Change
return array_merge($callbacks, $new_rules);
To
return array_merge($new_rules, $callbacks);
Read here Form_validation.php
OR
Without modifying core, you have to create on more callback function which does function of rule required like below
function required($str)
{
if(!is_array($str) ? (empty($str) === FALSE): (trim($str) !== ''))
{
$this->form_validation->set_message('from', 'Required error message');
return false
}
return true;
}
and in your controller
public function set_validation()
{
$this->form_validation->set_rules('from', 'Ended Date', 'callback_required|callback_compareDates');
}
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