Jump to content

Error checking for submission of a least one of three fields


dc_jt

Recommended Posts

I have a form with required fields to be
Name
Address
Town
City
Postcode
license
valid Email address

I then have three optional fields, photo, memory and data protection.

I have done the error checking for the required fields, however out of the three optional fields AT LEAST ONE must be entered.

I tried using the || but doesnt seem to work.

Any ideas??

if($_REQUEST[mode]=="apply"){
//error checking here

if(!$_REQUEST['name']){$_REQUEST[errors]['Name']='<div class="errors">Please enter your Name</div>';}
if(!$_REQUEST['address1']){$_REQUEST[errors]['Address']='<div class="errors">Please enter your Address</div>';}
if(!$_REQUEST['town']){$_REQUEST[errors]['Town']='<div class="errors">Please enter your Town</div>';}
if(!$_REQUEST['city']){$_REQUEST[errors]['City']='<div class="errors">Please enter your City</div>';}
if(!$_REQUEST['postcode']){$_REQUEST[errors]['Postcode']='<div class="errors">Please enter your Postcode</div>';}
if(!$_REQUEST['country']){$_REQUEST[errors]['Country']='<div class="errors">Please enter your Country</div>';}
if(!$_REQUEST['license']){$_REQUEST[errors]['License']='<div class="errors">Please agree to grant a license for the use of  your text/photo</div>';}
[b]if(!$_REQUEST['photo'] || !$_REQUEST['memory'] || !$_REQUEST['datap']){$_REQUEST[errors]['Photo']='<div class="errors">Please either enter a photo, memory or agree to the Data Protection Act</div>';}[/b] if(validateemail($_REQUEST['email'])===false){$_REQUEST[errors]['Email']='<div class="errors">Please enter a valid Email address</div>';}


if(sizeof($_REQUEST[errors])<1)
{
Used this

if(!$_REQUEST['photo']!="" || !$_REQUEST['memory']!="" || !$_REQUEST['datap']!=""){$_REQUEST[errors]['Optional']='<div class="errors">Please either enter a photo, memory or agree to the Data Protection Act</div>';}

And when none of the three were entered the error message came up which is correct.

However, when one was entered it still came up. Therefore, the error only comes up when all three are not entered.

Does that make sense??

Thanks

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.