Accept/Decline Button
Moderator: General Moderators
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Accept/Decline Button
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Accept/Decline Button
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.
(#10850)
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Accept/Decline Button
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.
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
Christopher...I understand what you are saying, but I'm not sure how to implement that...can you give me a code example?
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
Jonah...not sure with that either...code example?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Accept/Decline Button
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
@mattparsons Read some tutorials on forms. Here's a pretty good one:
http://www.w3schools.com/php/php_forms.asp
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
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.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Accept/Decline Button
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.
On the target page of the form, set maybe $_SESSION['did_accept'], and check to make sure it's set on page2.url.
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
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.
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
and @ Christopher...that header('Location...') function worked perfect. Thanks to you too. Now I just need the security thing and I'm set!
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Accept/Decline Button
Post your code so we can see what's wrong (don't forget the [syntax=php][/syntax] tags).
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
I already deleted it out of frustration and don't remember what I did...sorry. 
-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
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');
?>
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');
?>
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Accept/Decline Button
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).
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>');
}
?>-
mattparsons
- Forum Newbie
- Posts: 12
- Joined: Wed Nov 03, 2010 1:06 pm
Re: Accept/Decline Button
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"?