Welcome Guest, Not a member yet? Register   Sign In
Run individual validation scripts? - Validation Library
#1

[eluser]WoolyG[/eluser]
Hi,

Is it possible to run individual validation against a specified rule?

eg:

Code:
$rules['register_firstname']="required|xss_clean";

$register_firstname1 = $_POST['register_firstname'];
$register_firstname = mysql_real_escape_string($register_firstname1);

$test = $this->validation->run('register_firstname'); // This bit is probably setting me wrong
echo $test; // Expecting TRUE or FALSE


Cheers
WoolyG
#2

[eluser]Dennis Rasmussen[/eluser]
From the Documentation: http://ellislab.com/codeigniter/user-gui...ation.html

You set the rules with the set_rules method and as you can see in the documentation you can add as many rules for as many fields as you like - individually.

Code:
$this->load->library('form_validation');
            
$this->form_validation->set_rules('register_firstname', 'First name', 'required|xss_clean');  

if ($this->form_validation->run() == FALSE)
{
    echo 'Error!';
}
else
{
    echo 'Success!';
}
#3

[eluser]WoolyG[/eluser]
I understand that, but I want to individually state why each POST value is failing the validation in my return. I'm not loading a view from the results of the POST, I'm setting session values and redirecting, and as a result the form_error() functions are not displaying on my redirected pages..

WoolyG
#4

[eluser]CroNiX[/eluser]
You can also just store the validation errors in session and view them after the redirect.
#5

[eluser]Dennis Rasmussen[/eluser]
You can get individual errors with the form_error() function.

Documentation: http://localhost/CodeIgniter Doc/librari...dualerrors

Code:
foreach($_POST as $key => $value)
{
  if (form_error($key))
  {
    // session stuff
  }
}

Something like that?
I don't see the point of it though, but if that's what you need then so be it Smile




Theme © iAndrew 2016 - Forum software by © MyBB