CodeIgniter Forums

Full Version: help with two forms in one controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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}

El Forum

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:
if( array_key_exists( 'logged_in', $_POST ) )
    //run validation for 'logged in' form
elseif( array_key_exists( 'guest', $_POST ) )
    //run validation for 'guest' form