Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/26036-required-photo-or-another-field-in-form/
Share on other sites

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
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 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

??
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.