Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/85206-solved-birthdate-form-validation/
Share on other sites

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
}

?>

 

 

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.

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. ;)

<?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

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.