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

[eluser]Tom Schlick[/eluser]
well the login controller really isnt submitting any flashdata. the logout is so ill try that it should say "You are now logged out of your account".... we will see
#22

[eluser]Tom Schlick[/eluser]
ok i tried it on the logout controller. i removed the destroy session and now it only destroys the authenticating fields..

here is the logout controller code
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');
        echo $this->session->flashdata('info');
    }
}    
?>

when i click logout it doesnt display anything but if i refresh that screen it does say you have been logged out

this is the logout function in the user library
Code:
function logout()
    {
        $CI =& get_instance();
        $CI->session->unset_userdata('logged_in');
        $CI->session->unset_userdata('userID');
        $CI->session->unset_userdata('username');
    }
#23

[eluser]ontguy[/eluser]
From what I saw:
If when the logout controller is accessed the flashdata is set then it redirects to the login controller

If you echo the flashdata in the login controller, it should work as you intend it too.

If the echo works in the controller then the issue maybe with notice.tpl.
#24

[eluser]Tom Schlick[/eluser]
ok that works it will pass from logout to login but only if i do the echo from the controller and not pass it through anything (template library)

here is the logout:
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');
    }
}    
?>
here is the login:
Code:
<?php

class Login extends Controller
{
    function _construct()
    {
        parent::Controller();
    }
    
    function index()
    {
        echo $this->session->flashdata('info');
        /* if($this->session->userdata('logged_in'))
        {
            redirect('dashboard');
        }
        if($this->input->post('username'))
        {
            $this->load->helper(array('form', 'url'));
            $this->load->library('validation');
            $this->validation->set_error_delimiters('<div class="notice_red">', '</div>');
            $rules['username']    = "required|trim|alpha_numeric|max_length[20]|xss_clean";
            $rules['password']    = "required|max_length[40]|xss_clean";
            $this->validation->set_rules($rules);
            
            if ($this->validation->run() == FALSE)
            {
                $this->template_library->load('user/login.tpl');
            }
            else
            {
                $username = $this->input->post('username');
                $password = $this->input->post('password');
                log_message('debug', 'username and information declared in login function');
                $this->user_library->doLogin($username, $password);
            }
        }
        else
        {
            $this->template_library->load('user/login.tpl');
        } */
    }
}    
?&gt;
here is my template library code:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template_library
{    
    function load($stage, $tag_file = NULL, $lr = NULL)
    {
        $CI =& get_instance();
            $CI->session->keep_flashdata('info');
            if (file_exists(APPPATH.'tags/tags_global.php'))
            {
                include(APPPATH.'tags/tags_global.php');
                log_message('debug', 'TAGS: Global Tags Loaded');
            }
            if($tag_file != NULL)
            {
                if(is_array($tag_file))
                {
                    foreach ($tag_file as $name)
                    {
                        if (file_exists(APPPATH.'tags/tags_'.$name.'.php'))
                        {
                            include(APPPATH.'tags/tags_'.$name.'.php');
                            log_message('debug', 'TAGS: Tag File Tags Loaded');
                        }
                    }
                }
                else
                {
                    if (file_exists(APPPATH.'tags/tags_'.$tag_file.'.php'))
                    {
                        include(APPPATH.'tags/tags_'.$tag_file.'.php');
                        log_message('debug', 'TAGS: Tag File Tags Loaded');
                    }
                }
            }
            if(!isset($globals))
            {
                log_message('error', 'No Global Tags Available to Load - tags_global.php');
            }
            if(!isset($tags))
            {
                log_message('error', "No Global Tags Available to Load - $tag_file");
                $tags = array('nothing' => '');
            }
            if($lr != NULL)
            {
                $globals['lr'] = $lr;
            }
            else
            {
                $globals['lr'] = 'template/lr_default.tpl';
            }
            $globals['stage'] = $stage;
            //$tags = array_merge($tags, $others);
            $tags = array_merge($tags, $globals);
            $CI->smartyextended->view('template/main', $tags);
    }
    
    
    /*
    //    Dynamic Dropdown menus
    */
    function getDropdown($name, $table, $value = NULL)
    {
        $CI =& get_instance();
        $CI->load->model('template_model');
        $CI->load->helper('form');
        $data = $CI->template_model->getDropdownData($table);
        $form = "<select name='".$name."'>";
        $selected = "selected";
        
        if ($data->num_rows() > 0)
        {
           foreach ($data->result() as $row)
           {
              $form .= '<option value="'.$row->ID.'"';
              if($value == $row->ID)
              {
                  $form .= 'selected="'.$selected.'"';
              }
              $form .= '>'.$row->title."</option>\n";
           }
        }
        $form .= '</select>';
        return $form;
    }
}
?&gt;
#25

[eluser]ontguy[/eluser]
How does notify.tpl get involved?

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

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

be this?
Code:
{{if $CI->session->flashdata('good')}}

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

[eluser]Tom Schlick[/eluser]
no because with smarty it already gets the global variable because it is loaded in a library so we jsut remove the $this or $CI and it would be $session
#27

[eluser]beemr[/eluser]
[quote author="trs21219" date="1220645297"]when i click logout it doesnt display anything but if i refresh that screen it does say you have been logged out[/quote]

That must mean that your flashdata is being kept alive too long. You are using keep_flashdata('info') but only redirecting once. That's why it won't show up on logout unless the logout page is loaded twice.

If I remember right flashdata is given two properties -- 'new' or 'old'
'new' indicates that the flashdata was set by the current controller, so CI doesn't display it. 'old' indicates that the flashdata was set by the previous controller, so CI displays, and then the flashdata garbage collector deletes it.

The first time you logged out, you reset your flashdata to 'new' with keep_flashdata('info'). When you refresh your browser, that flashdata finally becomes 'old' and therefore elligible to be returned by the session->flashdata() call.
#28

[eluser]ontguy[/eluser]
What does the code to assign the flashdata to the smarty variable look like?

You've confirmed that the flashdata is getting to the controller. But not that smarty variable.
#29

[eluser]Tom Schlick[/eluser]
what do you want to see? the actual way smarty loads? for my thinking since all the other variables it passes to smarty such as the $session->userdata('something') <--- that passes so i dont think its the way smarty passes the information i think it has to do something with the way im loading it into that template library function or something of that nature. maybe it thinks its redirecting? or has too many page refreshes or something
#30

[eluser]ontguy[/eluser]
Still having trouble with the flashdata?

To me, since it getting to the controller, it has to be something with how it is being assigned or accessed from the library.




Theme © iAndrew 2016 - Forum software by © MyBB