Welcome Guest, Not a member yet? Register   Sign In
Validation_errors();
#1

[eluser]WebbHelp[/eluser]
Hi!

Sorry, it feels like I am posting thread after thread... but the positive thing is that I am learning a lot hehe Tongue
I hope I will pay you back later when I can more, and can help other people on the forum.

I am interesting in validation_erros(); I have used it, and I have got it to work.
But my question is more like:
If I, with my form, use the action to a function with the name submitgeneral, then on the controller page, and the submitgeneral function, I check for some errors, If there are any errors, the page will be shown again and show the errors.
How would I do then, in the best way I mean, this time i did like this:
In the submitgeneral function, I checked for errors, if there were any errors, I "called" a function generalsettings() that loaded the page with... I will show with some code:

Code:
public function generalsettings()
    {
        $data['menus'] = $this->db->query("SELECT id,menu FROM pages ORDER BY id ASC");
        $this->load->view('admin/general', $data);
    }
    
    function submitgeneral()
    {
        //Include the form_validation class
        $this->load->library('form_validation');
        //Check if the name field isn't empty(ignore space), the minimum length(2) and it clean the input from             XSS attacks.
        $this->form_validation->set_rules('name', 'Namn','trim|required|xss_clean');
        //Setting a own rule in function menucheck, the function checks if the menuchoice exists.
        $this->form_validation->set_rules('standard', 'Standard','callback_menucheck');
        // If form doesn't validate the rules, this is also false when the admin visit the page and then
        if ($this->form_validation->run() == false)
        {
            $this->generalsettings();
        }
        else
        {
            echo 'TJOHO';
        }
        
    }
}

You see, I call the function generalsettings if there are any errors and that function is loading the formular page.
Is that a good way to do it?
How should I do?
because if I use redirect(); I lose my validation_errors();

Thanks you //WebbHelp

If you don't understand my question just write som "???" and I try to explane it in another way Smile
#2

[eluser]WebbHelp[/eluser]
somebody?
#3

[eluser]Ben Edmunds[/eluser]
That way is fine. Another option is to save the validation_errors in flshdata to display but for what your doing your code should work fine.

One criticism though is tha you should create a model for your DB query.
#4

[eluser]WebbHelp[/eluser]
Ok, thanks Smile
I read my own thread again, but I nearly didn't understand what I wrote, I am happy you did haha Big Grin
I asking this because I want's to learn in the correct way at the beginning Smile

I am very glad you criticism like you did Smile
But... there is a problem... I am creating a CMS right now and I don't use models (wops).

I saw a tutorial, a movie-tutorial, he sad that models was the old way, so... I have never used it :S
I am not sure what it is eighter. hmm, this wasn't good, but I am glad you told me Smile

Thanks
#5

[eluser]Ben Edmunds[/eluser]
Not sure where you found that tutorial but you definitely want to use models.

Make sure you read up a little on MVC so you understand why.
#6

[eluser]WebbHelp[/eluser]
yes I will, but I didn' thought that was necessary when I heard that Smile




Theme © iAndrew 2016 - Forum software by © MyBB