dc_jt Posted November 2, 2006 Share Posted November 2, 2006 I have a form with required fields to be NameAddressTownCityPostcodelicensevalid Email addressI 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 https://forums.phpfreaks.com/topic/25905-error-checking-for-submission-of-a-least-one-of-three-fields/ Share on other sites More sharing options...
fiddy Posted November 2, 2006 Share Posted November 2, 2006 Why dont you try like this: if($_REQUEST['photo']!="" || $_REQUEST['memory']!="" || $_REQUEST['datap']!=""){ ..... } Link to comment https://forums.phpfreaks.com/topic/25905-error-checking-for-submission-of-a-least-one-of-three-fields/#findComment-118306 Share on other sites More sharing options...
dc_jt Posted November 2, 2006 Author Share Posted November 2, 2006 Used thisif(!$_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 https://forums.phpfreaks.com/topic/25905-error-checking-for-submission-of-a-least-one-of-three-fields/#findComment-118310 Share on other sites More sharing options...
dc_jt Posted November 2, 2006 Author Share Posted November 2, 2006 Sorted it using && instead of ||Thanks for the help anyway Link to comment https://forums.phpfreaks.com/topic/25905-error-checking-for-submission-of-a-least-one-of-three-fields/#findComment-118311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.