Welcome Guest, Not a member yet? Register   Sign In
Only validation library
#1

[eluser]Tominator[/eluser]
Hello there!

I've got one question: Is there any way how to make just validation library?

I mean: We use form validation library, which works like this:
Code:
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');

I am looking for something, which will check local variables, like this:
Code:
$name = 'Peter';

$this->validation->set_rules('name', 'trim|required|min_length[5]|max_length[12]|xss_clean]');

if ($this->form_validation->run() == FALSE)
{
// we can continue here
}

Thanks for your help.

Tom.
#2

[eluser]steelaz[/eluser]
AFAIK Validation library reads POST array, so if you set
Code:
$_POST['name'] = 'Peter';
before loading Validation library - you should be able to run it.
#3

[eluser]Tominator[/eluser]
Thank you steelaz for you answer, but you probably don't understand me.

Now I have to write somethink like this:
Code:
function Example($array)
{
  if (is_array($array) && !empty($array))
  {

    if (is_numeric($array['field1']) && !empty($array['field1']) && $array['field1'] > 3 ...
     && !empty($array['field2'] && strlen($array['field2']) > 3 && ...
     && ...)
     )

  }

// and here goes my script
}

It would be nice to have validation class, providing support for local variables (not just POST)
#4

[eluser]steelaz[/eluser]
I understand, but can you try doing this:
Code:
function Example($array)
{
    $_POST = $array;
    
    $this->load->library('form_validation');
    
    // Add some rules here

    if ($this->form_validation->run() == FALSE)
    {
        // Validation failed
    }

// and here goes my script
}
#5

[eluser]Tominator[/eluser]
Oh, I understand Big GrinD

Thanks for help!




Theme © iAndrew 2016 - Forum software by © MyBB