View Single Post
Old 01-16-2009, 02:16 AM   PM User | #1
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
Cases with Multiple Form Submissions

My form posts the data to the same page. Since there are multiple forms that could be submitted to the same page I need to have logic to determine which form is submitted. I would first create a switch to determine which form was submitted checking for a particular POST value. I need to create a hidden field on each form to identify the form.:

PHP Code:
if(isset($_POST)
{
    
//Form was submitted - determine the form
    
switch($_POST['formID'])
    {
        case 
"form1":
            
processForm1();
            
$page="xxx.php";
            break;
        case 
"form2":
            
processForm1();
            
$page="yyy.php";
            break;
    }

The $page value would represent which content to show in the page when it reloads. Although this may be different based upon the outcome of the form processing (i.e. form passed, form had invalid data, etc.)

So, now that I have a value ($page) to determine what content to show I could simply include it by default in the page.

PHP Code:
<div id=content>
<?php
    
if ($page)
    {
        include(
$page);
    }
?>
</div>
CoolAsCarlito is offline   Reply With Quote