CodeIgniter Forums
n00b asking about CI validation feature - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: n00b asking about CI validation feature (/showthread.php?tid=12510)



n00b asking about CI validation feature - El Forum - 10-22-2008

[eluser]Unknown[/eluser]
hi all,

i have problem with validation library

i do this simple example for education purpose, but i can't make it run correctly

why not working?

Code:
<html>
<head>
</head>
<body>
<?=$this->validation->error_string?>
<?=form_open('myform')?>
<?=form_input('testing')?>
<?=form_button('submit', 'submit')?>
<?=form_close() ?>
</body>
</html>

Code:
<?php
class myform extends Controller {
    public function index(){
        $this->load->helper(array('form', 'url'));
        $this->load->library('validation');
        $this->load->view('form');

        $rules['testing'] = 'required';
        $this->validation->set_rules($rules);

        if($this->validation->run() == true){
            var_dump($_POST);
        } else {
            echo 'validation not succeed';
        }
    }
}



n00b asking about CI validation feature - El Forum - 10-22-2008

[eluser]RogerM[/eluser]
Try this:
Code:
if ($this->validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }

Have a look at the user guides Validation Class for more details


n00b asking about CI validation feature - El Forum - 10-22-2008

[eluser]Unknown[/eluser]
but, im not going to load a view when the validation succeed, it cannot?

what if i want to load itself or running any function?


n00b asking about CI validation feature - El Forum - 10-22-2008

[eluser]RogerM[/eluser]
Simply add any code you need to.
The views were just an example. If it fails then it goes to the form with the Error message, else goes to the success form page/script.

Code:
if ($this->validation->run() == FALSE)
        {
            //reload form if failure occurs
        }
        else
        {
            //load success form validation
        }

Roger