Nothing preventing you from having one PHP file for all the steps.
You would just have the script proceed to "{$PHP_SELF}?step=1", "{$PHP_SELF}?step=2", etc.
and your script would be laid out:
if (isset($_POST['submit'])) {
// validate the form
} else {
// display the form
if ($_GET['step'] == 1) {
DO STUFF FOR STEP 1
} elseif ($_GET['step'] == 2) {
DO STUFF FOR STEP 2
} elseif ($_GET['step'] == 3) {
.
.
.
}
}
Also you should write a function 'validate_form' which you can pass a list of form items for each step that must be filled out. $required and $form are both arrays:
// We got errors the last time the form was submitted.
// We're just displaying them.
if ($_GET['errors'] != '') {
$errors = explode(',',$_GET['errors']);
foreach ($errors as $value) {
echo "You did not fill out an entry for the {$value} field.<br>\n";
}
}
function validate_form($required, $form) {
$errors = '';
foreach ($required as $key => $value) {
if ($form[$key] =='') {
$errors .= "{$key},";
}
}
return $errors;
}
// form validation
$errors = validate_form(array('name','email','phone1','city'),$_POST);
// we've validated the form and found errors, so we're going back to the same step and going to list the errors.
if ($errors != '') {
header ("$PHP_SELF."?step=".$_GET['step']."errors=".$errors);
}