I am trying to put validation on a variable value using set_rules
function from codeigniter. is it possible to do that?
My code is below :
$client_name = "Some name";
$this->form_validation->set_rules($client_name,'Client','required');
Even i have tried setting the value directly in Post variable as below :
$a = array('Name1','','Name3');
foreach($a as $client_name ) {
$_POST['client_name'] = $client_name = "Some name";
echo "--- " . validation_errors();
$this->form_validation->set_rules('client_name','Client','required');
if (!$this->form_validation->run())
{
echo validation_errors();
}
else
{
echo 'validation successful';
}
}
This code is giving below output:
--- // No validation error
validation successful //first time validation successfully ran
--- // No validation error
Client field is required //first time validation failed
--Client field is required // validation error from the second loop
Client field is required
Please help if it's possible.
Thanks in advance.