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)
{
Link to comment
Share on other sites

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
Link to comment
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.