Jump to content

if statement...


ashleek007

Recommended Posts

Hi All,

 

Just working on some form validation and have hit a problem... at the minute each error message displays individually of each other... but I want them to all display at the same time if the statements are true...  for example if someone hasnt put in their Title or Forename or Surname it should show all three error messages... heres the code below...

 

 


if ( $USER_VARS['TITLE'] == "" )
			{
				$USER_VARS['TITLE_ERR'] = "* Please select your Title from the list";
				return 0;
			}


			if ( strlen($USER_VARS['FORE']) > 0 )
			{
				if (!preg_match("/[a-z]+/", $USER_VARS['FORE'])) 
				{
				$USER_VARS['FORE_ERR'] = "* Please ensure First Name contains only letters (A-Z, upper and lower case), spaces, hyphens or apostrophes.";
				return 0;
				}
			}
			else
			{
				$USER_VARS['FORE_ERR'] = "* Please enter a First Name";
				return 0;
			}
			if ( strlen($USER_VARS['SURN']) < 1 )
			{
				$USER_VARS['SURN_ERR'] = "* Please ensure Surname contains only letters (A-Z, upper and lower case), spaces, hyphens or apostrophes.";
				return 0;
			}

			if ($USER_VARS['DOB_DAY'] == "Day")
			{
				$USER_VARS['DOB_ERR'] = "* Please select your Date of Birth";
				return 0;
			}

			if ($USER_VARS['DOB_MONTH'] == "Month")
			{
				$USER_VARS['DOB_ERR'] = "* Please select the month you were born on";
				return 0;
			}

			if ($USER_VARS['DOB_YEAR'] == "19")
			{
				$USER_VARS['DOB_ERR'] = "* Please select the year you were born on";
				return 0;
			}

			if ($USER_VARS['EMPLOYMENT'] == "Select Employment")
			{
				$USER_VARS['EMPLOYMENT_ERR'] = "* Please select your employment status from the list";
				return 0;
			}

 

Thanks for any help you guys can give,

Ash

Link to comment
https://forums.phpfreaks.com/topic/52621-if-statement/
Share on other sites

cheers all,

 

Daniel0... do you mean like this??

 


			if ($USER_VARS['EMPLOYMENT'] == "")
			{
				$USER_VARS['EMPLOYMENT_ERR'] = "* Please select your employment status from the list";
				$errors[] = $USER_VARS['EMPLOYMENT_ERR'];
			}

			if( count($errors) > 0 )
			{
			echo $errors[];
			}

 

Cheers,

Ash

Link to comment
https://forums.phpfreaks.com/topic/52621-if-statement/#findComment-259666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.