Page 1 of 2
Accept/Decline Button
Posted: Wed Nov 03, 2010 1:20 pm
by mattparsons
trying to make an "Agree to Terms of Service" page and want 2 buttons at bottom. 1. "Accept" where after the button is clicked, the page is redirected to the next page/step. 2. "Decline" where the user is redirected to a specific page. I also need the "Accepted" page to be accessible ONLY AFTER clicking the "Accept" button from the previous page. Any help out there?
Re: Accept/Decline Button
Posted: Wed Nov 03, 2010 6:42 pm
by Christopher
In PHP you would use the header("Location:
http://www.yourURL.com/to/next/page.php"); to do the redirects. To limit access to the Accepeted page, you will need to set a cookie or session variable when they click the Accept button. Then check that the cookie/session var is set on the Accept page.
Re: Accept/Decline Button
Posted: Wed Nov 03, 2010 6:44 pm
by Jonah Bron
Give each button a name and put them into a form. Say their names are "decline_btn" and "accept_btn". In the target page, check if either "accept_btn" or "decline_btn" are in $_POST or $_GET (whichever method you're using) using isset(). If accept_btn is there, display the page. If not, redirect to the decline page.
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 9:26 am
by mattparsons
Christopher...I understand what you are saying, but I'm not sure how to implement that...can you give me a code example?
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 9:36 am
by mattparsons
Jonah...not sure with that either...code example?
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 11:53 am
by Jonah Bron
Didn't see your answer there, Christopher...
@mattparsons Read some tutorials on forms. Here's a pretty good one:
http://www.w3schools.com/php/php_forms.asp
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 12:14 pm
by mattparsons
Hey Jonah...thanks for the reply...already got everything redirecting...buttons are working great and everything. The only thing I'm missing now is the security issue. I need to make it to where...if people just punch in the "page2.url" without clicking the "Accept" button on "page1.url", then they can't access the "page2.url" page. So...I'm trying the session variables...but I've never worked with them, so I don't really know how to use them properly and am getting nowhere. I hope that makes sense. And btw...your advice helped me get the buttons to work...thanks a lot.
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 12:31 pm
by Jonah Bron
http://www.w3schools.com/php/php_sessions.asp
On the target page of the form, set maybe $_SESSION['did_accept'], and check to make sure it's set on page2.url.
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 2:23 pm
by mattparsons
yeah...that's the stuff I've been trying to do , but it doesn't work...no errors, it just doesn't do anything at all.
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 2:27 pm
by mattparsons
and @ Christopher...that header('Location...') function worked perfect. Thanks to you too. Now I just need the security thing and I'm set!
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 2:50 pm
by Jonah Bron
Post your code so we can see what's wrong (don't forget the [syntax=php][/syntax] tags).
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 2:52 pm
by mattparsons
I already deleted it out of frustration and don't remember what I did...sorry.

Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 3:08 pm
by mattparsons
don't know if this helps you help me but...
HTML:
<div align="center">
<strong>By clicking the "Accept" button below, you are agreeing to ALL of the above policies.</strong>
</div><br />
<div align="center">
<form action="forms/check_opt.php"><input type="submit" name="opt" value="Accept"> <input type="submit" name="opt" value="Decline"></form></div>
PHP:
<?php
$opt=$_GET['opt'];
if ($opt=="Accept")
header ('Location:
http://www.url1.html');
else
header ('Location:
http://www.url2.html');
?>
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 3:20 pm
by Jonah Bron
For future reference, you should use a version control system (SVN, Git) when coding. That allows you to rollback and recover code from a previous point.
Are the HTML and PHP you gave on separate pages? First, you need to check if the "opt" box is there. We use isset() for that. In the first part of your If...else statement, put the session code. You also need to start the session. After the redirect, you must insert die() with a message, just in case the user's browser does not support redirection (extremely unlikely).
Code: Select all
<?php
session_start();
if (isset($_GET['opt']) && $_GET['opt'] == 'Accept') {
$_SESSION['did_accept'] = true;
header ('Location: http://www.url1.html');
die('<a href="http://www.url1.html">Click here to continue</a>');
} else {
header ('Location: http://www.url2.html');
die('<a href="http://www.url2.html">Click here to continue</a>');
}
?>
Re: Accept/Decline Button
Posted: Thu Nov 04, 2010 3:33 pm
by mattparsons
ok...yes they are separate pages...the php is in a forms folder (forms/check_opt.php) and the html is in the root folder(http://...url1.html). That code you gave worked perfect. Now how do I get the "url2.html" to check if the user clicked the "Accept" button from "url1.html"?