Welcome Guest, Not a member yet? Register   Sign In
Form validation OUTPUT problems
#1

[eluser]hugle[/eluser]
Hello Everyone.

I'm currently trying out CodeIgniter validation. And came up with some problems.

I have a function in my controller:

Code:
function register_form() {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('validation');
            
        $rules['username']    = "required";
        $rules['password']    = "trim|required|matches[passconf]";
        $rules['passconf']    = "required";
        $rules['email']        = "required|valid_email";
        
        $this->validation->set_error_delimiters('<li>', '</li>');
        
        $this->validation->set_rules($rules);
        
        $fields['username']    = 'Username';
        $fields['password']    = 'Password';
        $fields['passconf']    = 'Password Confirmation';
        $fields['email']    = 'Email Address';

        $this->validation->set_fields($fields);
            
        if ($this->validation->run() == FALSE)
        {
            $out = $this->load->view('myform');
        }
        else
        {
            $out = $this->load->view('formsuccess');
        }
        
        return ($out);
    }

(this function is basicaly from user guide)

Later, in 'function index' I do:
$content['middle'] = $this->register_form();

if I try to echo $content['middle'] I get empty page.

But If I for example try to navigate directrly index.php/register_form
I get myform.php view.


after some testings, I came up that:

when I change:
Code:
if ($this->validation->run() == FALSE)
        {
            $out = $this->load->view('myform');
        }
        else
        {
            $out = $this->load->view('formsuccess');
        }
to smth like:

Code:
if ($this->validation->run() == FALSE)
        {
            $out = "a";
        }
        else
        {
            $out = "b";
        }
I get output: "a" while accessing function index.


What I'm missing here or doing wrong?

Thanks everyone for help

cheers,
Jaroslav
#2

[eluser]Phil Sturgeon[/eluser]
The 3rd argument for the view method needs to be set to true to return output as a string. You are also not passing it any data in the 2nd parameter.
#3

[eluser]hugle[/eluser]
[quote author="thepyromaniac" date="1227210313"]The 3rd argument for the view method needs to be set to true to return output as a string. You are also not passing it any data in the 2nd parameter.[/quote]

thanks for suggestion Pyromaniac!

cheers!




Theme © iAndrew 2016 - Forum software by © MyBB