4 Replies - 1369 Views - Last Post: 09 November 2011 - 12:25 PM Rate Topic: -----

#1 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,841
  • Joined: 30-April 10

Php form back button issues

Posted 09 November 2011 - 11:09 AM

I am creating a registration form using one page with multiple parts (like a wizard) but I am using a session variable to hold what number form to present when the user clicks the next button.

For example:
<?php
//start session to hold variables for final script
session_start();

	//create session variable for form number to be viewed
	$_SESSION['form_num'];
	
	//if first time user entered registration page
	if(empty($_SESSION['form_num']))
	{
		//include first form table
		include("register_table.php");
		//set from number to 2
		$_SESSION['form_num'] = 2;
	}
	
	else if ($_SESSION['form_num'] == 2)
	{
		//include second form table
		include("register_table_2.php");
		//if user is band/artist
			//set form number to 3 for music information
		//if user is visitor
			//set form number to 4 for agreement of terms
	}
	
	else if ($_SESSION['form_num'] == 3)
	{
		//include third form table
		include("register_table_3.php");
		//set form number to 4
		$_SESSION['form_num'] = 4;
	}
	
	else if ($_SESSION['form_num'] == 4)
	{
		//include fourth form table
	}
//End session variables
//for registration
//Here
?>


is this the wrong way to do this? I am having a hard time figuring out how to make the user go back if they click the back button on say form 2,3,4..... Do i need to use something other than a session variable?

This post has been edited by laytonsdad: 09 November 2011 - 11:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Php form back button issues

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2911
  • View blog
  • Posts: 10,083
  • Joined: 08-August 08

Re: Php form back button issues

Posted 09 November 2011 - 11:13 AM

What's this?
$_SESSION['$form_num']
You don't have a session variable named $form_num. It's named the value of $form_num.
Was This Post Helpful? 2
  • +
  • -

#3 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,841
  • Joined: 30-April 10

Re: Php form back button issues

Posted 09 November 2011 - 11:19 AM

View PostCTphpnwb, on 09 November 2011 - 11:13 AM, said:

What's this?
$_SESSION['$form_num']
You don't have a session variable named $form_num. It's named the value of $form_num.

That is a miss type Thank you for catching that.
Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,841
  • Joined: 30-April 10

Re: Php form back button issues

Posted 09 November 2011 - 12:00 PM

I figured it out.


Register script
	if (!empty($_GET['back']))
	{
		$_SESSION['form_num'] -= 1;
	}



Form
<input name="back" id="back" type="button" value="Back" onclick="location.href='register.php?back=back'"/>


I guess I just need to think more before I ask for help.
Was This Post Helpful? 0
  • +
  • -

#5 dD3  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 16
  • Joined: 04-November 11

Re: Php form back button issues

Posted 09 November 2011 - 12:25 PM

the only problem with saving the steps in a session is that it will get mixed up when the user uses the browsers back button.

try using $_SERVER['HTTP_REFERER'] instead
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1