CodeIgniter Forums
validation - 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: validation (/showthread.php?tid=74655)



validation - aparedesv - 10-20-2019

Hi,

in CI3, I use the form_validation library some this:

$this->form_validation->set_rules('text_es', $this->lang->line('text').' '.$this->lang->line('castella'), 'min_length[2]');
$this->form_validation->set_rules('text_en', $this->lang->line('text').' '.$this->lang->line('angles'), 'min_length[2]');
$this->form_validation->set_rules('text_fr', $this->lang->line('text').' '.$this->lang->line('frances'), 'min_length[2]');

if ($this->form_validation->run() == FALSE)
{
$this->ecosistema(2, $this->input->post('ecosistema_id'));
}
else

{
// done
}

what's in CI4?

thanks!


RE: validation - aparedesv - 10-21-2019

after trying,

$validation->setRule('nom', lang('Admin.nom', [], $idioma), 'required|min_length[2]|max_length[100]');
$validation->setRule('cognoms', lang('Admin.cognoms', [], $idioma), 'required|min_length[2]|max_length[100]');

if(!$validation->withRequest($this->request)->run())


RE: validation - InsiteFX - 10-21-2019

CodeIgniter 4 User Guide - Validation


RE: validation - EvilMoe - 10-29-2019

How can I just verify my rules on a submit? I followed the User Guide. But it is not clear enough for me. Since I set my Rules even on the first load I get all the errors which makes sense. How can I avoid it in the CI4 way?

Here is the controller:

       
PHP Code:
helper(['form''url']);
$validation =  \Config\Services::validation();
    
        
        $validation
->setRules([
            'username' => ['label' => 'username''rules' => 'required|min_length[5]'],
            'password' => ['label' => 'password''rules' => 'required|min_length[5]']
        ]);

      
        
        
if ($validation->withRequest($this->request)->run()) {
            // Input was OK
        

        echo view('Login', ['validation' => $validation]); 

In my view I have:

Code:
<div><?php echo $validation->listErrors(); ?></div>