form validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

form validation

Post by chris_s_22 »

i want to vaidate the user input of a form
the form uses 3 dropdown boxes named
dobday values 1-31
dobmonth values jan-dec
dobyear values 2009 - 1900

i want to only allow people aged over 16 im guessing i will need to call current day month year and do some can of maths but havent got a clue how to structure it.

i know im using a dropdown so user can only select one of the values but i also want to double check a make sure each feild is one of the values(this help prevent people using there own forms)
so what to also check
dobday = a single or double number ranging from 1-31
dobmonth = can only be letters being between 3(shortest month) characters and 9(longest month) characters
dobyear = 4 digit number between 2009 and 1900

ive been told theres some programs that can do the form validation for me. i did find and try it but it didnt satisfy all my requirements.

can any one recomend any that could do what i am asking. i dont mind paying if it is a decent one
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: form validation

Post by Eric! »

Assuming you know php and how to process a form...you can use the get_age function I posted here about 5 posts down viewtopic.php?f=1&t=102259
to verify they are over 16.

That will be one million dollars. :|
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: form validation

Post by Eric! »

Damn, I have to remember: cash first, then code....
guru2k9
Forum Newbie
Posts: 9
Joined: Fri Oct 30, 2009 6:24 am

Re: form validation

Post by guru2k9 »

Hi,

Use the below code, This will help you to calculate the age

<?php
$birthday = '07-07-2004';
$today = date('d-m-Y');

$a_birthday = explode('-', $birthday);
$a_today = explode('-', $today);

$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];
$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];

$age = $year_today - $year_birthday;

if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}
?>

Thanks
Post Reply