dc_jt Posted November 3, 2006 Share Posted November 3, 2006 I have a form with fields which must be required such as name, address, town, city etc.I then need to have a photo, a memory field and a data protection tick box, for which at least one must be selected.I tried this but it only works for the memory field and the data protection. If a user only chooses to insert a photo the error still occurs.[quote]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>';} 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>';} if(validateemail($_REQUEST['email'])===false){$_REQUEST[errors]['Email']='<div class="errors">Please enter a valid Email address</div>';} [/quote]I think it might have something to do with the [quote]if(!$_REQUEST['photo']!="" [/quote]I tried using [quote]if(!$_FILES['photo']!="" [/quote] but the rror doesnt come up at all then. Any ideas??Thanks Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/ Share on other sites More sharing options...
.josh Posted November 3, 2006 Share Posted November 3, 2006 if (!$a && !$b && !$c) { // echo error} Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119026 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 Hi,Do you need two NOT (!) . (if(!$_REQUEST['photo']!="" && !$_REQUEST['memory']!="" && !$_REQUEST['datap']!=""){)I dont know what you are trying to do there but i guess it should be like if($_REQUEST['photo']!="" ..... Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119028 Share on other sites More sharing options...
dc_jt Posted November 3, 2006 Author Share Posted November 3, 2006 It doesnt matter about the datap now, thats not required its just the photo and memory.i tried this:[quote]if(!$_REQUEST['memory'] || !$_FILES['photo']){$_REQUEST[errors]['gukhk']='<div class="errors">Please enter either a photo or a memory</div>';}[/quote]And that works, so if memory is only inserted thats fine, however if just a photo is inserted, it still throw the error message.Any idea?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119030 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 Can you pls try with OR (|).(if($_REQUEST['photo']=="" || $_REQUEST['memory']=="" && $_REQUEST['datap']==""){) Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119039 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 Sorry , my previous post was wrong Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119041 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 i ment this. Sorry about my previous one(if($_REQUEST['photo']=="" && $_REQUEST['memory']=="" && $_REQUEST['datap']==""){) Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119043 Share on other sites More sharing options...
dc_jt Posted November 3, 2006 Author Share Posted November 3, 2006 I have got it working for photo now by doing:[quote]if($_FILES['photo']['error'] != UPLOAD_ERR_OK){$_REQUEST[errors]['Optional']='<div class="errors">Please enter either a photo or a memory</div>';}[/quote]However, i need to put the or memory bit in somewhere.I tried[quote]if($_FILES['photo']['error'] != UPLOAD_ERR_OK || !$_REQUEST['memory']{$_REQUEST[errors]['Optional']='<div class="errors">Please enter either a photo or a memory</div>';}[/quote] But then neither would work?? Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119044 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 Can you pls try this:(if($_REQUEST['photo']=="" && $_REQUEST['memory']=="" && $_REQUEST['datap']==""){) Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119048 Share on other sites More sharing options...
dc_jt Posted November 3, 2006 Author Share Posted November 3, 2006 [quote author=fiddy link=topic=113709.msg462332#msg462332 date=1162550426]Can you pls try this:(if($_REQUEST['photo']=="" && $_REQUEST['memory']=="" && $_REQUEST['datap']==""){)[/quote]That works for the memory part but not for the photo!Have a look at my above post, thats how you get the photo part working but i cant put them together now ha?? Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119049 Share on other sites More sharing options...
dc_jt Posted November 3, 2006 Author Share Posted November 3, 2006 Think ive done it, was using or instead of and when putting them together Quote Link to comment https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/#findComment-119050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.