Welcome Guest, Not a member yet? Register   Sign In
n00b asking about CI validation feature
#1

[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';
        }
    }
}
#2

[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
#3

[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?
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB