Click to See Complete Forum and Search --> : No idea


NickG21
01-12-2007, 08:26 AM
hey everyone, i don't mean to nag but if anyone can tell me a good way to to create a subscription style site that uses 6 different forms/form pages. all i want to do is display one at a time and when....
Part 1 is submitted, it goes through validation, if it doesn't pass, Part 1 is redisplayed, if it does
Part 2 is displayed........and so on and so forth

I have tried this using a switch, if...elseif using include(), include_once(), require() and i just cannot get it right, either the validation works incorrectly or the next page loads wrong and so on. if anyone can point me somewhere it would be wonderful
thanks in advance
nick

NogDog
01-12-2007, 02:20 PM
I'd use sessions to keep track of all the data that's been entered, allowing you to pre-populate forms if validation requires you to go back.

<?php
session_start();
?>
...
<input type="text" name="example" value="<?php
if(isset($_SESSION['example']))
{
echo htmlspecialchars($_SESSION['example'], ENT_QUOTES);
}
?>">

Then when you process the form:

<?php
session_start();
foreach($_POST as $key => $val)
{
$_SESSION[$key] = (get_magic_quotes_gpc()) ? stripslashes($val) : $val;
}

Note that this requires that all the form elements across all the pages have unique names (or at least all those whose values need to be kept track of).