Solved

PHP - form workflow

Posted on 2008-06-22
7
183 Views
Last Modified: 2012-06-27
Hi,

Say I have a TermsAndAgreement.php which contains 2 radio buttons (I Agree|I Disagree) and submit button. Upon choosing one of the radio buttons, then clicking "Submit" then it should go to Signup.php.

What php code do i put in signup.php & TermsAndAgreement.php, so it checks to ensure the user has clicked on "I Agree" previously, else it redirects it back to TermsAndAgreement.php.

Also if the user select "I Disagree", how do i redirect it to readthis.php

Thanks!
0
Comment
Question by:jedistar
  • 5
  • 2
7 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 21841594
Here is an example to help get you started.  Run that and you will see how the variable come through from the form to the subsequent script.
<?php 

if (!empty($_POST)) {

	var_dump($_POST); // SHOW THE POST VARIABLES

}

?>

<form action="<?=$PHP_SELF?>" method="post">

<input name="agreement" type="radio" value="agree" />Agree

<input name="agreement" type="radio" value="disagree" />Disagree

<input type="submit" name="go" value="go" />

</form>

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 21841608
This will take you to signup.php (note the action= keyword).
<form action="signup.php" method="post">

<input name="agreement" type="radio" value="agree" />Agree

<input name="agreement" type="radio" value="disagree" />Disagree

<input type="submit" name="go" value="go" />

</form>

Open in new window

0
 

Author Comment

by:jedistar
ID: 21841630
if the user goes to signup.php directly, how do i prevent the user from seeing the signup.php if he has not agreed to the terms.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jedistar
ID: 21841633
and be redirected back to the terms page
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 21841631
This will process the $_POST input in signup.php.  I would recommend that you NOT redirect - instead give the client a clear message and let them click the link.  The redirect is likely to be confusing.  You might have to code some kind of GET string, etc.
<?php 
 

/* COMMENT OUT - REMOVE THIS BLOCK

if (!empty($_POST)) {

	var_dump($_POST); // SHOW THE POST VARIABLES

}

*/
 

$agreement	= $_POST["agreement"];
 

if ($agreement == 'disagree') {

	echo "<a href="readthis.php">You checked Disagree.  Please read this.</a>\n";

}
 

if ($agreement != 'agree') {

	echo "<a href="TermsAndAgreement.php">You must check Agree or Disagree.  Please try again.</a>\n";

}

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 21841635
In signup.php, you just process the $_POST input.  If it's not what you're expecting, don't worry - just give the client the links to the pages he needs to read.  Easy!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 21841642
Although I would recommend not doing it, the general form of a "redirect" is shown below.  This one redirects to the home page.  Note the "exit" -- the header command will be executed to send the header, then your script will go right on executing the instructions.  You need the exit() function to tell it to stop.
header("Location: /");

exit;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now