CodeIgniter Forums
Loading the form and validating in the same function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Loading the form and validating in the same function? (/thread-30015.html)

Pages: 1 2


Loading the form and validating in the same function? - El Forum - 04-29-2010

[eluser]parham90[/eluser]
Duh! And I thought through some magic trick I'd never come to understand, this code example I saw on the net works like a charm! Smile

Thanks a lot, and sorry for causing you all frustration.


Loading the form and validating in the same function? - El Forum - 04-29-2010

[eluser]Ivan A. Zenteno[/eluser]
But why your controller is like that? I mean the controllers is like then:

Code:
function foo()
{
    $rules = array('THE RULES HER');
    $this->form_validation->set_rules($rules);
    if($this->form_valitaion->run())
    {
       //foo true
    }
    else
    {
       //var false
    }
}



Loading the form and validating in the same function? - El Forum - 04-30-2010

[eluser]parham90[/eluser]
Yes, I read that piece of code I wrote (well, something like that) somewhere on the Internet. I assumed the rules have to be set only when the page is loaded as a form, and therefore, the strange form you saw. It is fixed now, though.


Loading the form and validating in the same function? - El Forum - 04-30-2010

[eluser]skunkbad[/eluser]
If you'd like to see a working example of form validation and posting to the same method, you might check out the add_category method on this page:

http://bitbucket.org/skunkbad/community-cart/src/tip/application/controllers/inventory.php


Loading the form and validating in the same function? - El Forum - 04-30-2010

[eluser]parham90[/eluser]
Thanks! A great tip. Smile