Welcome Guest, Not a member yet? Register   Sign In
how to redirect to welcome controller without removing validation_errors ();
#1

[eluser]my9006ci[/eluser]
i have welcome controller
Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
    }
    
    function index()
    {   $this->load->library('login');
        $data['body'] = $this->login->login();
        $this->load->view('body',$data);
    }
}
    
?>
and i have login library
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login {

    var $CI = null;
    public function __construct(){
        $this->CI =& get_instance();
    }
    function Login() {
        $result = '';
        $result .= $this->CI->login->form();
        return $result;
    }
    function form() {
        $result .= validation_errors();
        $result .= form_open('login/login/',array('id'=>'loginform'));
        $result .= form_label('What is your Name').''.form_input(array('name'=>'username','class'=>'input'));
        $result .= form_label('Your Password').''.form_password(array('name'=>'password','class'=>'input'));
        $result .= form_submit(array('name'=>'button','class'=>'submit','value'=>'Login'));
        $result .= form_close();
        return $result;
    }
}

?>
and i have login controller
Code:
<?php

class login extends Controller {
    
    function login()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?>
I want to replace
Code:
$this->load->view('myform');
and
Code:
$this->load->view('formsuccess');
how to redirect to welcome controller without removing validation_errors ();
#2

[eluser]daelsepara[/eluser]
you can use session flashdata:

Code:
$this->session->set_flashdata('validation_errors', 'put the error message here');
redirect('welcome');

in your welcome controller:

Code:
if ($this->session->flashdata('validation_errors')) $data['validation_errors'] = $this->session->flashdata('validation_errors');

in your welcome views:

Code:
&lt;?php if (!empty($validation_errors)) print "<div class = \"error\">$validation_errors</div>\n"; ?&gt;
#3

[eluser]mddd[/eluser]
I think part of the problem is in the fact that your form's target is a different page then where the form is on.
Now you have a page with a login form, and a page that shows 'your are logged in', but also has to show the form again in case of errors!
So, there are two places that have to handle the form.

I think it's a better solution to post the form to its own url. If there are problems, you can show them there. In the same form you are using already.
In the login library, you check if everything is okay, and if it is, you redirect the user to the "you are logged in" page.
#4

[eluser]my9006ci[/eluser]
[quote author="daelsepara" date="1276267798"]you can use session flashdata:

Code:
$this->session->set_flashdata('validation_errors', 'put the error message here');
redirect('welcome');

in your welcome controller:

Code:
if ($this->session->flashdata('validation_errors')) $data['validation_errors'] = $this->session->flashdata('validation_errors');

in your welcome views:

Code:
&lt;?php if (!empty($validation_errors)) print "<div class = \"error\">$validation_errors</div>\n"; ?&gt;
[/quote]

good idea
@daelsepara thanks




Theme © iAndrew 2016 - Forum software by © MyBB