Welcome Guest, Not a member yet? Register   Sign In
How to use method setRule?
#1

Sorry for my bad English.

Today I read Official User Guide about Validation Library. From the very beginning, the tutorial on this library has been going sequentially, but after the setRule() methods it breaks off and there is no logical conclusion just like a tutorial. I don't understand how to work the next code:

PHP Code:
$validation->setRule('username''Username''required'); 
  
Ok! I set up one rule for my form field. In tutorial wrote about it, but how to use and run the next checking? If in the condition I leave the code as in the example below, then the method setRule() has no effect. My form do not show any errors after send. What should I write in the condition if()? Another words - how to activate validation mechanism?

In my Controller I have:

PHP Code:
$validation =  \Config\Services::validation();

$validation->setRule('username''Username''required');

if (! 
$this->validate([]))
  {
            echo view('Signup', [
                'validation' => $this->validator
            
]);
  }
  else
  {
      echo view('Success');
  


and further... about 
Code:
withRequest()
In what cases can this method be applied? Can I have a simple example?

Thanks in advance.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB