Jump to content

Recommended Posts

i was wondering if anyone had a good way to make a page display one page at a time.  I have been trying by passing a hidden variable but i am unable to do error handling on each individual page. 
[code]<?php
session_start(); <--- at top of page
        IF (!isset($_POST['step'])) {
  include "ListInfo.php";}  <----first form page

ELSEIF ($_POST['step'] == 2){
  include "OptServices.php";} <------ second form page

ELSEIF ($_POST['step'] == 3){
include "ContInfo.php";}<------third form page

ELSEIF ($_POST['step'] == 4){
include "BillInfo.php";}<----fourth form page

ELSEIF ($_POST['step'] == 5){
include "Survey.php";}<----fifth form page

ELSEIF ($_POST['step'] == 6){
include "Terms.php";} <--- sixth form page
?>[/code]
and in each page i include validation code with this as a way to switch to the other form, this is the part i can't get right
[code]
session_start();
foreach($_POST as $key => $var) {
$_SESSION[$key] = $var;
}
if (isset($_POST['ListInfo']))
{
$errorList = array();
}

if(empty($NameForList)){
$error[] = "List Name";
} <-----more validation code------>

if(count($errorList) > 0){
$errors = "<p class=\"error\"><big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $errorList). "</p>";
}ELSE{
echo "<input type='hidden' value='2' name='step'>";
include_once('headerImage.php');
}[/code]  the pages initially display with all of the errors showing and when passed to the next form the previous one comes up underneath full of the input......any ideas?
Link to comment
https://forums.phpfreaks.com/topic/33792-including-multiple-pages/
Share on other sites

First of all I'd use a switch: [code]<?php
session_start(); // just because you had it, no need for this code if it's the only

switch($_POST['step'])
{
case '1':
include 'ListInfo.php';
break;
case '2':
include 'OptServices.php';
break;
// etc...
default: // sort of like the "else" in this. it is if the other values won't "work"
include 'home.php';
break;
}
?>[/code]

For the other file (read comments!): [code]<?php
session_start();
foreach($_POST as $key => $var)
{
$_SESSION[$key] = $var;
}

if(isset($_POST['ListInfo']))
{
$errorList = array();
}

if(empty($NameForList)) // where does this come from??
{
$error[] = "List Name"; // is it supposed to add to $errorList instead of $error?
}

// more validation

if(count($errorList) > 0)
{
$errors = "<p class=\"error\"><big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $errorList). "</p>";
}
else {
echo "<input type='hidden' value='2' name='step'>";
include_once('headerImage.php');
}
?>[/code]
in order to use a switch wouldn't i have to post to headerImage.php where the include statement is?  i was trying to keep the validation in the form page (ListInfo.php etc...) and the error messages still echo when the page is initially loaded and when the first page is submitted with correct information the second form is loaded and the first one is included underneath still.

Any help would be great
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.