Uzm Posted January 9, 2008 Share Posted January 9, 2008 Hey! Yesterday i've met a little problem with form validation for birthdate entries that my users enter on my registration page, so i'm asking for a little assistance from you guys. I have three forms on my registration page: select-menu named "birth_date_year", select-menu "birth_date_month" and "birth_date_day". What i want to decline submissions that HAVE selected a value from "birth_date_year", but NOT "birth_date_month" and/or "birth_date_day", or in other way. I've tried with operators, but it seems not to work. Anyone could help me with this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/ Share on other sites More sharing options...
Mordax Praetorian Posted January 9, 2008 Share Posted January 9, 2008 I'm not great with php, but my instinct would be to go with staggered if statements, i.e: if (condition){ if (condition){ if (condition){ code; } } } Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434712 Share on other sites More sharing options...
pocobueno1388 Posted January 9, 2008 Share Posted January 9, 2008 So basically you want to make sure they have supplied a complete birthday? If you are using selects, then I will assume your first option looks something like this. [tt]<option value="none">Please Select Day/Month/Year</option> <?php if ($birth_date_year == 'none' || $birth_date_month == 'none' || $birth_date_day == 'none'){ echo "ERROR, you didn't fill out a complete birthday"; } else { //they supplied all 3 fields, continue } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434723 Share on other sites More sharing options...
Uzm Posted January 9, 2008 Author Share Posted January 9, 2008 pocobueno1388: Thanks for a nice solution, but that wasn't really what i was searching for. I'll try to explain a little closer. Loads of users that registrate themselves on that page, only choose their birthdate month and day, but not YEAR. So, what i want to do is to check, IF year, month OR day has been choosed - but not not the complete birthdate-forms (year/month/day) - for instance if user chooses only his year of birthdate, but doesn't choose day or month of birthdate - user will receive an error. Also, i want to give a apportunity to users not to select their birthdate. So that's really the problem itself. Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434729 Share on other sites More sharing options...
chronister Posted January 9, 2008 Share Posted January 9, 2008 I am still unclear here. Birthday is optional as a whole, but if they verify the b-day it has to contain specific pieces of the b-day string?? is this pretty close? Nate Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434775 Share on other sites More sharing options...
Uzm Posted January 9, 2008 Author Share Posted January 9, 2008 All right. Let say, that we have 3 SELECT-menus. First is named "1", second "2", and third "3". User has to choose values from ALL select-menus. But instead of choosing ALL of them, user only chooses SELECT-menu "1", and doesn't choose anything from second and third menu. I want to deny those kinds of submits. If user chooses something from first menu, then he/she HAS to choose a value from second and third menu aswell. Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434778 Share on other sites More sharing options...
chronister Posted January 9, 2008 Share Posted January 9, 2008 <?php if ($birth_date_year != 'none' || $birth_date_month != 'none' || $birth_date_day != 'none'){ // at least one item has been selected, so lets see if they all have been selected if ($birth_date_year == 'none' || $birth_date_month == 'none' || $birth_date_day == 'none'){ //at least one is empty so give an error echo "ERROR, you didn't fill out a complete birthday"; } else { //they supplied all 3 fields, continue } } ?> Is this kinda what your looking for?? If at least one is selected, then make sure all of em are selected, otherwise none have been selected, so skip it. Hope it helps Nate Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434788 Share on other sites More sharing options...
Uzm Posted January 9, 2008 Author Share Posted January 9, 2008 Thank you chronister, that's exactly what i was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/#findComment-434849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.