Welcome Guest, Not a member yet? Register   Sign In
Form Validation only Works When User is Logged In??
#1

[eluser]Tom Schlick[/eluser]
This one has been really puzzling me for the past couple of weeks. We have it setup so the user logs into thier account to manage all of their stuff and interact with our site. but we have noticed that the validation messages on the forms only show up when the user is logged in. same with the flashdata. this is a big problem because most of the validation is for the registration and login pages where the user is obviously not logged in...

here is some of the source code see if anyone can make any sense of this....
logout.php
Code:
<?php

class Logout extends Controller
{
    function _construct()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->user_library->logout();
        $this->session->set_flashdata('info', 'you have been logged out');
        redirect('login');
    }
}    
?>

then that redirects to login...

now we have a central file that has the notificaitons for flashdata... its called notice.tpl (since we are using smarty.) its included in every page and is this...

Code:
{{if $session->flashdata('good')}}

    <div class="notice_green">{{$session->flashdata('good")}}</div>
    

{{elseif $session->flashdata('error')}}

    <div class="notice_yellow">{{$session->flashdata('error")}}</div>
    

{{elseif $session->flashdata('bad')}}

    <div class="notice_red">{{$session->flashdata('bad")}}</div>
    

{{elseif $session->flashdata('info')}}

    <div class="notice_blue">{{$session->flashdata('info")}}</div>
    
{{/if}}

again it works if you are logged in... but not if you are not

if someone could help i would greatly greatly appriciate it... thanks
#2

[eluser]drewbee[/eluser]
Is the session library still being called on pages that you are not logged in on?

Also, when you are calling your logout() method, are you destroying the session? I am not positive, but the new session may not regenerate until the next page load, hence you are saving the flash data on logout to a unknown/invalid session.
#3

[eluser]Tom Schlick[/eluser]
the session library is autoloaded so for everypage it should be there. your right this was a bad example for it because i am destroying the session when i logout but for say the register page it submits it and it does validate but it doesnt display the errors... so i was thinking it was a session problem with a session not being created so the errors had no where to save to. if you want i can send you some code on a pm because its a bit sensitive and i dont want to post it to the world.
#4

[eluser]drewbee[/eluser]
Is this error page shown on the same page (view include) as the form when errors occur, or does the user have to do a 'goback' type of situation?
#5

[eluser]Tom Schlick[/eluser]
its included via smarty into every page. so we have like our wrapper with menus, sidebar etc and then the body and the error page is included to the top of every body page. and it looks for the flashdata of error, info, good, or bad and displays the correct error delimiters (css classes) and then shows the content of that flashdata within...
#6

[eluser]drewbee[/eluser]
I'd say as a quick test, what happens if you set these values with the the normal session value (set_userdata) instead of flashdata? It almost sounds as if (maybe because of a redirect or the like) it is hitting the second page, removing the flash data, then forwarding on; leaving you with empty flash data.
#7

[eluser]Tom Schlick[/eluser]
ok now i am logged in so i have a session and i tried this and it didnt work

Code:
&lt;?php

class Dashboard extends Controller
{
        //Constructor
        function Dashboard()
        {
                parent::Controller();
                //Load the language file
                $this->lang->load('dashboard', $this->config->item('language_code'));
        }
        //Default function
        function index()
        {
                $this->session->set_userdata('info', 'testing... testing...');
                $this->template_library->load('user/dashboard_stage.tpl', 'user', 'user/user_lr.tpl');
        }
    
}

?&gt;

here is the notice file

Code:
{{if $session->flashdata('good')}}

    <div class="notice_green">{{$session->flashdata('good")}}</div>
    

{{elseif $session->flashdata('error')}}

    <div class="notice_yellow">{{$session->flashdata('error")}}</div>
    

{{elseif $session->flashdata('bad')}}

    <div class="notice_red">{{$session->flashdata('bad")}}</div>
    

{{elseif $session->userdata('info')}}

    <div class="notice_blue">{{$session->flashdata('info")}}</div>
    
{{/if}}
#8

[eluser]Tom Schlick[/eluser]
ok so i have come to the conclusion that the flashdata is not working no matter where i put it and the validation errors only work if the person is logged in( have a session).
#9

[eluser]beemr[/eluser]
[quote author="trs21219" date="1220480043"]... so i was thinking it was a session problem with a session not being created so the errors had no where to save to.[/quote]

The Validation class doesn't report errors to the session's flashdata. There are specific functions that belong in your view for either an error summary or a message for each erroneous field (check out the user guide). Flashdata is for passing messages between URI's. Validation is essentially a reload upon fail and a redirect upon success.
#10

[eluser]Tom Schlick[/eluser]
yes i know that i have the appropriate $this->validation->error_string; in there...




Theme © iAndrew 2016 - Forum software by © MyBB