Jump to content

Form is not using the php code


rockman

Recommended Posts

Hello everyone! This is my first post here! I was hoping I could get some help! I'm trying to create an age gate form and I'm running into a problem. The index page that I created actually works fine, but when I create the form and set up the php code the form is not interacting with the data beyond the action. I really don't understand what's going on here. I have a verify.php page that has a form on it and the php that should interact with it is at the top like so:

<?php
session_start();

if(isset($_POST['submit']))
{
	$remember = $_REQUEST ['remember'];
	$day = $_POST ['day'];
	$month = $_POST ['month'];
	$year = $_POST ['year'];
	$country = $_POST ['country'];
	
	$birthday = mktime(0,0,0,$month,$day,$year);
	$difference = time() - $birthday;
	$age = floor($difference / 31556926);
	
	echo $age;
		
	if($age >= 21)
	{
		$_SESSION ['verifyok'] = 1;
		header ("location: index.php");
	}
	else
	{
		$_SESSION ['verifyfail'] = 0;
		header("loaction: http://www.centurycouncil.org/");
	}
	if($remember == 'save')
	{
		setcookie("verifyok", 1,mktime(0,0,0,01,01,date("Y")+30));
		$_SESSION['verified'] = 1;
		header("location: index.php");
		exit(0);
	}
}
?>

And here I have the form that does not interact with the php and has the action as verify.php, the test server works and the php at the top of my index.php does redirect me to the verify page, but the verify page just isn't working.

<form action="verify.php" method="POST">
<span class="heading">ENTER YOUR BIRTH DATE</span>
<div id="dob">
<select name="day" class="styled" />
<option selected="selected" disabled="disabled">DD</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month" class="styled" />
<option selected="selected" disabled="disabled">MM</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
<select name="year" class="styled" />
<option selected="selected" disabled="disabled">YYYY</option>
<option>2013</option>
<option>2012</option>
<option>2011</option>
<option>2010</option>
<option>2009</option>
<option>2008</option>
<option>2007</option>
<option>2006</option>
<option>2005</option>
<option>2004</option>
<option>2003</option>
<option>2002</option>
<option>2001</option>
<option>2000</option>
<option>1999</option>
<option>1998</option>
<option>1997</option>
<option>1996</option>
<option>1995</option>
<option>1994</option>
<option>1993</option>
<option>1992</option>
<option>1991</option>
<option>1990</option>
<option>1989</option>
<option>1988</option>
<option>1987</option>
<option>1986</option>
<option>1985</option>
<option>1984</option>
<option>1983</option>
<option>1982</option>
<option>1981</option>
<option>1980</option>
<option>1979</option>
<option>1978</option>
<option>1977</option>
<option>1976</option>
<option>1975</option>
<option>1974</option>
<option>1973</option>
<option>1972</option>
<option>1971</option>
<option>1970</option>
<option>1969</option>
<option>1968</option>
<option>1967</option>
<option>1966</option>
<option>1965</option>
<option>1964</option>
<option>1963</option>
<option>1962</option>
<option>1961</option>
<option>1960</option>
<option>1959</option>
<option>1958</option>
<option>1957</option>
<option>1956</option>
<option>1955</option>
<option>1954</option>
<option>1953</option>
<option>1952</option>
<option>1951</option>
<option>1950</option>
</select>
</div>
<span class="heading" id="heading2">ENTER YOUR LOCATION</span>
<div id="location">
<select name="country" class="styled" id="country" />
<option>USA</option>
</select>
</div>
<div id="cookie">
<div id="box"><input type="checkbox" name="remember" value="save" class="styled" /></div><span id="notice"><b>Remember Me</b><br>
<i>Do not check this box if you use a shared computer.</i>
</span>
</div>
<div class="clear"></div>
<div id="button">
<input id="enter" type="image" name="submit" src="images/enter_inactive.png" WIDTH="117" HEIGHT="44" BORDER="0" ALT="SUBMIT!">
</div>
</form>

I put a couple of divs inside the form but I don't see how that would really effect the PHP at all, the whole form is still together. I can't even get an echo test to work. I'm completely stumped here. I would greatly appreciate some help! Thanks You!

Edited by rockman
Link to comment
Share on other sites

 

if(isset($_POST['submit']))
<input id="enter" type="image" name="submit" src="images/enter_inactive.png" WIDTH="117" HEIGHT="44" BORDER="0" ALT="SUBMIT!">

 

An image submit button generates x/y values rather than just it's name, so you have to test for $_POST['submit_x'] and $_POST['submit_y']. Alternatively you could change your test to some other field, or change the submit button to use a <button> tag.

<button name="submit"><img src="images/enter_inactive.png"></button>
If desired, you can use CSS to remove the button's default styling so you only see the image.
Link to comment
Share on other sites

Thanks kicken, I will keep that in mind for next time, but I just decided to go with if($_POST) for the time being. I still value this because I would have enver known this was the case with type=image otherwise.

Link to comment
Share on other sites

As kicken said, you can and in my opinion, should change the button to something other than image. Input type = image with an array name freaks out IE as well. (Post's the Y value instead of the actual value.)

 

http://stackoverflow.com/questions/2357184/input-type-image-name-and-value-not-being-sent-by-ie-and-opera#comment23771450_2357184

 

Okay, mabye I will change this then! Also, it seems that when I submit the data it takes me to the verify page again. Then I have to do the form again, then it sends me to the corect site. Not sure what's going on there.

<?php
session_start();

if(isset($_SESSION['verifyok']))
{
	header("location: index.php");
}
if(isset($_SESSION['verifyfail']))
{
	header("location: http://www.centurycouncil.org/");
}

if($_POST)
{
	$remember = $_REQUEST ['remember'];
	$day = $_POST ['day'];
	$month = $_POST ['month'];
	$year = $_POST ['year'];
	$country = $_POST ['country'];
	
	$birthday = mktime(0,0,0,$month,$day,$year);
	$difference = time() - $birthday;
	$age = floor($difference / 31556926);
			
	if($age >= 21)
	{
		$_SESSION ['verifyok'] = 1;
		header ("location: index.php");
	}
	else
	{
		$_SESSION ['verifyfail'] = 0;
		header("loaction: http://www.centurycouncil.org/");
	}
	if($remember == 'save')
	{
		setcookie("verifyok", 1,mktime(0,0,0,01,01,date("Y")+30));
		$_SESSION ['verified'] = 1;
		header("location: index.php");
		exit(0);
	}
}
?>
Edited by rockman
Link to comment
Share on other sites

you need an exit; statement after every one of your header() redirects to prevent the remainder of your code from running while the browser is requesting the target url of the redirect.

 

fyi - all the browsers send the _x and _y coordinates for a type='image' form field because that's what the w3.org specification states is to be submitted. the other browsers that send more than that are doing it outside of the specification and have caused more work and confusion behind the scenes (which is what specifications and following them are meant to prevent.)

Link to comment
Share on other sites

you need an exit; statement after every one of your header() redirects to prevent the remainder of your code from running while the browser is requesting the target url of the redirect.

 

fyi - all the browsers send the _x and _y coordinates for a type='image' form field because that's what the w3.org specification states is to be submitted. the other browsers that send more than that are doing it outside of the specification and have caused more work and confusion behind the scenes (which is what specifications and following them are meant to prevent.)

 

For some reson it keeps looping and the redirects are not working, so if I get the verification right it doesn't save the session I just go to index and it attempts to redirect be back to the verification page!

Link to comment
Share on other sites

a) if would help if you showed the code on your index page that checks if someone is logged in.

 

b) you are likely redirecting back and forth between variations of your domain name with and without the www. on them and by default the session id cookie only matches the variation of your domain where it was set at.

Link to comment
Share on other sites

a) if would help if you showed the code on your index page that checks if someone is logged in.

 

B) you are likely redirecting back and forth between variations of your domain name with and without the www. on them and by default the session id cookie only matches the variation of your domain where it was set at.

 

On the index.php page I think I had this and I'm on a test server so all I really had was just a location: verify.php

<?php
session_start();

if(!isset($_SESSION['verifyok'])){
	header("location: verify.php");
	exit;
}
?>


So it just checks if there is no set session and redirects if there is not.

Link to comment
Share on other sites

In your original code, you are redirecting BEFORE you set the "remember" cookie.

 

Also, you are setting the "verifyok" element of the session to 1 or 0. So a test with isset($_SESSION['verifyok']) is going to be TRUE regardless of the VALUE in that element.

 

I'm not sure if either of these is causing the loop, but they are going to cause some minor headaches at some point.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.