Log in

View Full Version : Help with a script to deline members of a certain age



Rob (SA)
01-17-2011, 06:57 PM
Hi folks,

I have an entry form which has a date of birth input requirement and the format of input is YYYYMMDD i.e 19920819 being born on the 19 August 1992.

I do however want to limit 1992 models from entering information and should they submit the form then a pop up should appear saying sorry you are too old to enter these events?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>entryform</title>
<meta name="KEYWORDS" content="GAUTENG,NORTH">
<meta http-equiv="Page-Enter" content="revealTrans(Duration=1,Transition=2)">
<meta name="GENERATOR" content="Created by BlueVoda">
<style type="text/css">
div#container
{
width: 752px;
position: relative;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
text-align: left;
}
body
{
text-align: center;
margin: 0;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
function Validateentryform(theForm)
{
if (theForm.Editbox1.value == "")
{
alert("Please enter your NAME");
theForm.Editbox1.focus();
return false;
}
if (theForm.Editbox1.value.length < 3)
{
alert("Please enter your NAME");
theForm.Editbox1.focus();
return false;
}
if (theForm.Editbox1.value.length > 35)
{
alert("Please enter your NAME");
theForm.Editbox1.focus();
return false;
}
if (theForm.Editbox4.value == "")
{
alert("Please enter a value for the \"Please enter your SURNAME\" field.");
theForm.Editbox4.focus();
return false;
}
if (theForm.Editbox4.value.length < 3)
{
alert("Please enter at least 3 characters in the \"Please enter your SURNAME\" field.");
theForm.Editbox4.focus();
return false;
}
if (theForm.Editbox4.value.length > 35)
{
alert("Please enter at most 35 characters in the \"Please enter your SURNAME\" field.");
theForm.Editbox4.focus();
return false;
}
var strFilter = /^[-+]?\d*\,?\d*$/;
var chkVal = theForm.Editbox3.value;
if (!strFilter.test(chkVal))
{
alert("Date of Birth ? ? (YYYYMMDD)");
theForm.Editbox3.focus();
return false;
}
if (theForm.Editbox3.value == "")
{
alert("Date of Birth ? ? (YYYYMMDD)");
theForm.Editbox3.focus();
return false;
}
var strFilter = /^[-+]?\d*\.?\d*$/;
var chkVal = theForm.Editbox5.value;
if (!strFilter.test(chkVal))
{
alert("Please enter your CELL NUMBER (i.e 083 . . . . . . ) no spaces");
theForm.Editbox5.focus();
return false;
}
if (theForm.Editbox5.value == "")
{
alert("Please enter your CELL NUMBER (i.e 083 . . . . . . ) no spaces");
theForm.Editbox5.focus();
return false;
}
if (theForm.Editbox5.value.length < 10)
{
alert("Please enter your CELL NUMBER (i.e 083 . . . . . . ) no spaces");
theForm.Editbox5.focus();
return false;

fileserverdirect
01-17-2011, 07:30 PM
On the processor page, you should convert "19 August 1992" into milliseconds, then convert their entered date to milliseconds, then use a simple if($age<$age18) to check. I suggest looking at http://php.net/manual/en/function.strtotime.php to help you convert the dates automatically.

Rob (SA)
01-17-2011, 07:34 PM
Hi,

The conversion of 19 August 19920 is not the challenge. The person inputs the data already in the format of YYYYMMDD and hence to me it would just be an if / else statement whereby . . .if the first four numbers are smaller than 1992 . .. . then you're to old would pop up and submission to MySQL terminated.

Else submission continues as per normal.

I just do not know how to do this in php.

Thanks again for your advice.

fileserverdirect
01-17-2011, 07:44 PM
Your not seeing the purpose of strtotime. You have to convert both their age and the date into an interger in terms of milliseconds since 1970:
however you cannot use the YYYYMMDD format. tell them to use YYYY-MM-DD format in order to convert.


$age=strtotime($_POST['age']);
$agelimit=strtotime("19 August 1992");
if($age<$agelimit)header("location: error.htm");

Rob (SA)
01-17-2011, 07:49 PM
Thanks for the reply and script.

In using this script would it be specific to 19 August 1992 or would it be specific to all persons born in 1992?

Secondly taking your script into consideration where would I insert it using the PHP file presented below?

The page I refer to is seen at this link (http://www.gnjgf.co.za/entryform.php)
Regards
Rob

fileserverdirect
01-17-2011, 07:54 PM
1st Make sure you change your date entry to YYYY-MM-DD or any other Unix-compatible timestamp.
2nd. Set your form action to "processor.php"
3rd Paste the code in that file and it should redirect if the age is less.
4th Place the rest of your processing code beneath that.

Rob (SA)
01-17-2011, 08:04 PM
Hi Ben,

Thanks for the reply.

As a person who does not have any idea of php - my experiance to do what you ask is very limited -my apologies.

The information I have been able to give is by using a wysiwyg website builder and therefor can get to show you what I have my apologies - I hope it is also not asking to much.

Regards
Rob

fileserverdirect
01-17-2011, 08:07 PM
Do you have FTP access? Or any type of file access?

Rob (SA)
01-17-2011, 08:10 PM
Yes I do

fileserverdirect
01-17-2011, 08:13 PM
Do you have any type of form processor already set up (or maybe built in to the editor). In other-words does the form submit normally now and work?

Rob (SA)
01-17-2011, 08:17 PM
Hi,

I have a form processor and the form seen on that link does actually work and submit.

I use Bluevoda and the form processor is something call ABVFP.

Regards
Rob

fileserverdirect
01-17-2011, 08:28 PM
Hmm, I see, That seems to be a pre-factured processor and im not really sure how you could add this age plugin to that. It may be better to age validate through javascript, this would be a simmilar approach.

After quick googling, I found http://www.kuranes.co.uk/utils/agecheck.html


<script language="javascript">
function checkAge()
{
/* the minumum age you want to allow in */
var min_age = 8;
var max_age = 18;

/* change "age_form" to whatever your form has for a name="..." */
var year = parseInt(document.forms["age_form"] ["year"] .value);
var month = parseInt(document.forms["age_form"] ["month"] .value) - 1;
var day = parseInt(document.forms["age_form"] ["day"] .value);

var theirDate = new Date((year + min_age), month, day);
var today = new Date;

if ( (today.getTime() - theirDate.getTime()) < 0) {
alert("Get Out, Scum!");
return false;
}
else {
return true;
}
}
</script>

HTML:


<form action="http://www.kuranes.co.uk" method="get" name="age_form">
Day : <select name="day">
<option>1</option>
<option>2</option>

<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>

<option>9</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>

Month : <select name="month">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>

<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>

<option>12</option>
</select>

Year : <select name="year">
<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>
<option>1949</option>
<option>1948</option>
<option>1947</option>
<option>1946</option>

<option>1945</option>
<option>1944</option>
<option>1943</option>
<option>1942</option>
<option>1941</option>
<option>1940</option>

<option>1939</option>
<option>1938</option>
<option>1937</option>
<option>1936</option>
<option>1935</option>
<option>1934</option>

<option>1933</option>
<option>1932</option>
<option>1931</option>
<option>1930</option>
<option>1929</option>
<option>1928</option>

<option>1927</option>
<option>1926</option>
<option>1925</option>
<option>1924</option>
<option>1923</option>
<option>1922</option>

<option>1921</option>
<option>1920</option>
<option>1919</option>
<option>1918</option>
<option>1917</option>
<option>1916</option>

<option>1915</option>
<option>1914</option>
<option>1913</option>
<option>1912</option>
<option>1911</option>
<option>1910</option>

<option>1909</option>
<option>1908</option>
<option>1907</option>
<option>1906</option>
<option>1905</option>
<option>1904</option>

<option>1903</option>
</select>

<input type="submit" name="_send_date_" value="Go" onClick="return checkAge()">
</form>
</div>

However this is veering from PHP and of course it will not work if you disable javascript. You may want to post in the javascript section of this site for further help if you run into problems.

Rob (SA)
01-17-2011, 08:35 PM
Thanks for your help.

Javascript can also work and I will try the other link offered.

Again the challenge is how to insert it?

I appreciate your help

Regards
Rob

fileserverdirect
01-17-2011, 08:39 PM
Paste the javascript code into the current javascript you provided my with, and then use the select boxes for the date of birth, but yes, I suggest you make a javascript topic about this and how to implement it, as javascript is not my forte.

Rob (SA)
01-17-2011, 08:43 PM
Will do thanks Ben