04-06-2015, 10:51 AM
(04-04-2015, 04:31 PM)ruiganga Wrote: This way doesn't work. Data is neve valid. Always that is NOT valid.
$this->form_validation->set_rules($email , 'Users email', 'required|valid_email');
if ($this->form_validation->run() == FALSE)
{
echo " Submitted data IS NOT valid";
}
else
{
echo " Submitted data IS valid";
}
$email is the variable where I put the valid email to test. Am I doing something wrong?
Yes, you are.
The form validation do not take variables like that. The first value, where you have $email, is the name of the POST data in global $_POST array. As in my example, lets say that in the AJAX request you do, you send a parameter called 'user_email'. In the controller you send the request to, that 'user_email' data will be available in the global $_POST array as $_POST['user_email']
So, in $this->form_validation->set_rules(); you set the first option to 'user_email' as that is the name of the your data in the global $_POST array.
If you for some reason don't have the data available in the global $_POST array anymore, then you can validate any other type of array. So, in your case, you could create a new array with your email and then set that as the array that form validation should validate.
Here is an example.
PHP Code:
$validate_data = array('email' => $email);
$this->form_validation->set_data($validate_data);
$this->form_validation->set_rules('email' , 'Users email', 'required|valid_email');
if ($this->form_validation->run() == FALSE)
{
echo " Submitted data IS NOT valid";
}
else
{
echo " Submitted data IS valid";
}
More info about validation an array here http://www.codeigniter.com/userguide3/li...-than-post