CodeIgniter Forums
$this->validation->withRequest($this->request)->run() behavior - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: $this->validation->withRequest($this->request)->run() behavior (/showthread.php?tid=67890)



$this->validation->withRequest($this->request)->run() behavior - donpwinston - 04-20-2017

CI4's $this->validation->withRequest($this->request)->run() behaves differently then CI3's $this->form_validation->run()?

When the page is loaded and no submit button is clicked CI3 will return FALSE. It appears CI4 returns TRUE.
I had to do the following:

if ($this->request->getVar('submitted') == NULL || ! $this->validation->withRequest($this->request)->run())


Is this the way it's supposed to work?


RE: $this->validation->withRequest($this->request)->run() behavior - kilishan - 04-20-2017

Yes, that's the way it's currently designed. There's a simpler way to use it, though.

From the manual:

Code:
class Form extends Controller
{
    public function index()
    {
        helper(['form', 'url']);

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