Jump to content

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

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.