Re: Many forms in one php file

From: Date: Tue, 15 Feb 2005 12:21:29 +0000
Subject: Re: Many forms in one php file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-208714@lists.php.net to get a copy of this message
Nsk wrote:
Hi I want to create a single php file which will be able to display multiple html forms. Like this: Form1 -> Form2 -> Form3. After the user completes and submits Form1, the script will process it and display a different form. etc... I am new to php, I would need some detailed instructions, or point me to an opensource php script which already does that so that I can analyse it.
In a single script it could be a little nasty if you want more then one or two phases - its common to have a submit and view result on the same script, but multiple stages can become a maintaince nightmare, but you can do it like this: You could use a "mode" indicator and a session settings. Look for start_session() in the manual. Something like: <?php start_session(); if(!isset($_SESSION['mode'])){ $_SESSION['mode'] = 0; // first time round, on first screen } // function to test if mode is 0 AND button pressed (ie a submission, // deal (store) the information and increment mode if($_SESSION['mode'] == 0){ ?> <form 1> </form 1> <?php } else if ($_SESSION['mode'] == 1) { ?> <form 2> </form2> <?php } ?>

« previous php.general (#208714) next »