Welcome Guest, Not a member yet? Register   Sign In
validation_errors() is breaking my view...
#1

[eluser]theapache[/eluser]
Hey guys.

Ok, got a login form working great with the form validation library.

So I set up a function to allow users to create a folder in my app (it's a file host app) and I use the form validation library once again.

This is where the problem starts. The moment I put the validation_errors() call in my view, the view breaks and displays no output on render. Not only that, but the same thing happens to my login view which has the validation_errors() call. Displays nothing but fresh white space. It's like the function call in one view is breaking the function call in another view... So weird!

The moment I remove the validation_errors() call from either view, both render fine.

Has anyone run across this happening in their app?

Just for a little background info, both forms have their own controller and the form validation library is loaded and run in separately in each respective controller.

Thanks for any help!
#2

[eluser]xzela[/eluser]
Could you post the part of your controller which validates the post? It sounds like there a problem with the placement of your $this->load->view().

What's most likely the issue is that there is an conditional case where the controller is not given the instructions to print a view.

That'd be my guess without seeing the code.
#3

[eluser]theapache[/eluser]
It's a pretty simple function. I posted the relevant code snippets below.

Code:
class Filepit extends Controller {

    function Filepit()
    {
        parent::Controller();
        $this->load->helper('url');    
        $this->load->library('session');
        $this->load->model('Users');
        $this->load->model('Files');
        $this->load->model('Folders');
    }


    
    ...
    


    function show_create_folder_form()
    {
        $this->load->view('header');
        $this->load->view('forms/new_folder');
        $this->load->view('footer');
    }
    
    function do_create_folder()
    {
        $user_id = $this->uri->segment(3);
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('folder_name', 'Folder name', 'trim|required|alpha_numeric');
        
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('header');
            $this->load->view('forms/new_folder');
            $this->load->view('footer');
        }
        else
        {    
            if ($this->Users->create_folder_for_user($user_id, $this->input->post('folder_name')))
            {
                $this->session->set_userdata('msg', 'Your folder was created successfully.');
                redirect('folder/all_files');
            }
        }
    }



        ...
    
}


show_create_folder_form is called when a user clicks the *new folder* button. And then depending on whether or not the validation_errors() call is in the new_folder view, that page will load or not. When I take the call out the view loads up. But when it's in, nothing is rendered.

Here's the view:
Code:
&lt;?php if (isset($msg)): ?&gt;<p>&lt;?php echo $msg; ?&gt;</p>&lt;?php endif; ?&gt;
&lt;?php echo validation_errors(); ?&gt;
&lt;form id="new_folder" action="&lt;?php echo site_url('filepit/do_create_folder/' . $this-&gt;session->userdata('user_id')); ?&gt;" method="post">
    <fieldset>
        &lt;input type="text" id="folder_name" name="folder_name" /&gt;
        <label for="folder_name"><small><em>Folder name</em></small></label>
        &lt;input type="submit" class="submit" value="Create it" /&gt;
    </fieldset>
&lt;/form&gt;

Interestingly, if I put the validation_errors call below the form, the header & footer view will not load at all, but the new_folder form will.
#4

[eluser]xzela[/eluser]
One quick question: Do you have PHP error messages turned on? I bet that blank page is an error message, but because PHP is set to not show errors, you don see anything. This would explain why the views are unexpectedly breaking.
#5

[eluser]evolutionxbox[/eluser]
I think xzela is correct... also try setting the error delimiters to be div's or something simple so you know it cannot be that.
#6

[eluser]Zack Kitzmiller[/eluser]
Where are you setting $msg? I don't see that in your code anywhere.

All I see is you setting the session variable 'msg'.
#7

[eluser]theapache[/eluser]
Morning guys,

Just took a look at this again and it's still pretty much acting the same.

@xzela: My error reporting has been set at 4 and no errors have been logged at any time.

@evolution: I tried setting the delimiters to divs just for the heck of it, but no difference.

@techneke: Ahh thank you for mentioning this. I must have placed the $msg print statement in the view by mistake before adding the validation_errors call in and just left it there thinking it was necessary. The only time 'msg' is set in the session is when a folder is successfully created on the server, then the user is redirected to a different controller (folder/all_files) and this controller checks to see if 'msg' is set in the session, and if so places it in the data array and passes it to my main app view.




Theme © iAndrew 2016 - Forum software by © MyBB