473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Terms and Conditions Form, 1 Checkbox redirect to another page

Hi I have a basic form, all it has on it is a checkbox with terms and conditions, the user has to check the box to say I agree, the problem I am having is the page is echoing the correct information out but is not redirecting the user if they check the box.

The Php code is in include statement in the form page which is layed out via css etc etc.

The code I have is

Expand|Select|Wrap|Line Numbers
  1. $submit = $_POST['submit'];
  2. $agree = $_POST['agree'];
  3.  
  4. if (isset ($_POST['agree'])) {
  5.  
  6.     echo "<h3>You agree to our terms</h3>";
  7.     header('Refresh: 10; URL=searcher.php');
  8.  
  9. } else echo "<h3>You Disagree, you must agree before using our database</h3>";
  10.  
  11.  
I have also tried

Expand|Select|Wrap|Line Numbers
  1. $submit = $_POST['submit'];
  2. $agree = $_POST['agree'];
  3.  
  4. if (isset ($_POST['agree'])) {
  5.  
  6.     echo "<h3>You agree to our terms</h3>";
  7.     header('Location: searcher.php');
  8.  
  9. } else echo "<h3>You Disagree, you must agree before using our database</h3>";
I have tried using the variables set but nothing works when I do

Can anyone tell me where I am going wrong?

Be grateful for some help as I am getting nowhere fast with this.

Thanks in advance.
Mar 12 '11 #1
16 5765
  1. Make sure your form is set to submit using HTTP POST, not GET. (method="post")
  2. Make sure you checkbox is named "agree" (name="agree") and have some non-empty value (value="AGREED")
  3. In the back-end code check if the value is empty or not.

Expand|Select|Wrap|Line Numbers
  1. if(empty($_POST['agree'])) {
  2.     //Not agreed
  3. }
  4. else {
  5.     //Agreed
  6. }
Mar 13 '11 #2
Thanks for the reply but I am missing something, what you have given me is half working i9n that it redirects to the page required but it also redirects if checkbox not ticked, what have I missed?

Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="post" action="search.php">
  2. <label for="agree">Agree</label>
  3.           <input type="checkbox" name="agree" id="agree" />
  4.  
  5. <input type="submit" name="submit" id="submit" value=" Agree " />
The page with the form is search.php so it is posting back to itself

the php script included in the form is

Expand|Select|Wrap|Line Numbers
  1. <?php include 'php/termscond.php'; ?>
and the script is as follows now

Expand|Select|Wrap|Line Numbers
  1. if(empty($_POST['agree'])) {
  2.  
  3.     echo "<h3>You must agree before accessing our database</h3>";
  4. }
  5. else {
  6.     header('Location: searcher.php');
  7. }
The header is not working although the search.php and searcher.php are at same level in directory in same folder.

Thanks in advance for your help
Mar 13 '11 #3
Code you have posted above works fine. Maybe some other part of the code is interfering with the redirection.

Here's what I tested:
search.php
Expand|Select|Wrap|Line Numbers
  1. <?php include 'termscond.php'; ?>
  2. <form id="form1" name="form1" method="post" action="search.php">
  3. <label for="agree">Agree</label>
  4.           <input type="checkbox" name="agree" id="agree" />
  5.  
  6. <input type="submit" name="submit" id="submit" value=" Agree " />
  7. </form>
termscond.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(empty($_POST['agree'])) {
  3.  
  4.     echo "<h3>You must agree before accessing our database</h3>";
  5. }
  6. else {
  7.     header('Location: searcher.php');
  8. }
Mar 13 '11 #4
So in your test when you did not check the box you were advised to check or you could not use the search facility but you were kept on the terms page?

When you checked the box you were redirected?
Mar 13 '11 #5
yes, it only goes to the searcher.php if the checkbox is checked.
Mar 13 '11 #6
Would it be possible for you to just have a quick look at the pages concerned, to see if you can spot why it is not working for me then please?
Mar 13 '11 #7
Sure, Please post the complete and latest code you are trying out.
Mar 13 '11 #8
Link to search page

The php code is exactly what you suggested earlier, I just cannot seem to work out why I cannot get it working especially as you have said it worked for you.
Mar 13 '11 #9
Your HTML form seems to be ok. I think the problem might be in http://www.da-ict.co.uk/php/termscond.php
Please post the complete PHP code of that file.
Mar 13 '11 #10
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if(empty($_POST['agree'])) {
  3.  
  4.     echo "<h3>You must agree before accessing our database</h3>";
  5. }
  6. else {
  7.     header('Location: searcher.php');
  8. }
  9.  
  10.  
  11. ?>
Thanks for this, especially when you said you had it working it threw me even more.
Mar 13 '11 #11
Hmm, that's the same code I tried on my local server and it worked. But I clearly see it's not working on yours.

Can you add error_reporting(E_ALL); on top of all the pages involved in this process and see if you are getting any errors?
And, instead of the redirect echo some text and see of the program flow reaches that section.

Oh, and add a value to your check box.
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" id="agree" name="agree" value="yes">
Mar 14 '11 #12
As the rest of the site is being tested I have re-saved the terms and conditions page under http://www.da-ict.co.uk/searchtcs.php until the issue is resolved.

I have put the value="yes" in the checkbox.

If I echo text out instead of the redirect the action works, the correct text is echoed out depending on the condition so does that point to the header('Location: searcher.php'); of the php script?

If you look at http://www.da-ict.co.uk/searchtcs.php I have just left echo text statements in place depending on the checkbox condition the correct one is output but when I put the header back in that just doesnt work.
Mar 14 '11 #13
The error log shows the following

Expand|Select|Wrap|Line Numbers
  1. [14-Mar-2011 13:29:03] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  2. [14-Mar-2011 13:29:08] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  3. [14-Mar-2011 13:31:00] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  4. [14-Mar-2011 13:31:31] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  5. [14-Mar-2011 13:31:39] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  6. [14-Mar-2011 13:36:04] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
  7. [14-Mar-2011 13:36:08] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/daictcou/public_html/searchtcs.php:4) in /home/daictcou/public_html/php/termscond.php on line 22
This is obviously when I am using the header rather then the echo that is currently on the page.
Mar 14 '11 #14
When you redirect using header() there shouldn't be any output generated before that.
Make sure you don't have any echo or HTML output before the redirect.

You can try buffering the output to avoid this http://php.net/manual/en/function.ob-start.php

also place an exit() right after the header()
Mar 14 '11 #15
Sudaraka, thank you very much for your help with this, it was driving me mad, that seems to have fixed it.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start();
  3. session_start();
  4. ?>
at the top of the form page

the php looks like

Expand|Select|Wrap|Line Numbers
  1. if(empty($_POST['agree'])) {
  2.  
  3.     echo "<h3>You must agree before accessing our database</h3>";
  4. }
  5. else {
  6.     //echo "<h3>You agree with our terms</h3>";
  7.     header('Location: ../searcher.php');
  8.  
  9. }
and it seems to bge working now.

Once again thanks
Mar 14 '11 #16
Good to hear you got it working, glad to help.
Good luck with rest of the project.
Mar 14 '11 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nazir | last post by:
I am trying to do something pretty simple - but can't see how it can be done in ASP.NET. I have an aspx web page with a form which opens up a new window. The web page uses code behind to build...
4
by: Andrea De Santi | last post by:
How can I redirect to another page with form data? In asp Classic I write: <form ... action="filename">...</form> and in then target page I write <%=request.form("fieldname")%> ..... but in...
2
by: KFactor | last post by:
Is it possible to pass form variables to a page on another server using response.redirect? Or is there a secure way of passing sensitive information from one site to another such as a userID? ...
2
by: Luongo | last post by:
Hi, I have a form that, when submitted, needs to be processed by one file (survey.php) but have another page (thankyou.php) displayed. Because I don't have access to the former, I can't combine the...
11
by: dkate777 | last post by:
Hi, Is anybody know how to pass textbox input value to another page. I am using document.secondform.fieldname.value=document.firstformname.fieldname.value but it's not working Thanks
1
by: mentor | last post by:
in first page, <form id="form1" runat="server" action="page2.aspx"> <TEXTAREA id="txt1" runat=server></TEXTAREA> <INPUT type=submit value=submit name=rev_submit> in second page(c#) string...
2
by: Hamayun Khan | last post by:
Hi I have Two pages Default.aspx and Default2.aspx Default.aspx has the following code <%@ Page Language="VB" MasterPageFile="~/Main.master" AutoEventWireup="false"...
1
by: Wolfman | last post by:
Hi gang! I've been searching for a solution to this problem extensively but nothing really hits the mark. I have a descriptive popup page that contains a PayPal order button. The normal PayPal...
6
djsjm
by: djsjm | last post by:
Hi there, Beg of your forgiveness if this is too basic or the question has already been answered somewhere... I'm still learning my way around php and this site. I have a form on page 1 which...
2
by: ssmeshack85 | last post by:
Hai there, Im using ASP .NET C#. Here I have a few checkboxes in page 1. When hit the next button that link to page2, I want checkboxes that checked send it's details to the textbox in page 2. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.