CodeIgniter Forums
help with two forms in one controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: help with two forms in one controller (/thread-26655.html)



help with two forms in one controller - El Forum - 01-19-2010

[eluser]dadamssg[/eluser]
Im trying to figure out the most efficient way up setting of validation for two forms on the same page. I have different form for a logged in user and for a not logged in guest and they each need their own validation rules. How should i set this up? i have it set up like below but i don't know where to put the guest comment validation

function index()
{
validation rules for logged in user comment
if(validation is true)
{insert comment}
load header
load topic
if(logged in)
{show comment form}
else{show guest comment form}
}


help with two forms in one controller - El Forum - 01-19-2010

[eluser]theprodigy[/eluser]
Well, you could have your two forms submit to different functions and setup validation that way. Or you could place hidden form elements in your form and do something like:
Code:
if( array_key_exists( 'logged_in', $_POST ) )
{
    //run validation for 'logged in' form
}
elseif( array_key_exists( 'guest', $_POST ) )
{
    //run validation for 'guest' form
}