Jump to content

Setting an image field as a default?


Solarpitch

Recommended Posts

Hey Guys,

 

In my application I have 6 image fields. If a user uploads an image they must upload an image 1 which is the main image. So I dont want them to be able to jump to the 2nd or 3rd fields and upload their file there.

 

I am just not sure how to go about defaulting them to upload image 1 first?

Link to comment
https://forums.phpfreaks.com/topic/77050-setting-an-image-field-as-a-default/
Share on other sites

If you have 6 input fields like Wuhtzu suggest, you should be able to use javascript (if it's possible in your application?) to disable all fields but the first one, and then enable the next field each time the previous is not empty anymore, if you get me?

I can see 3 solutions:

 

#1: Use javascript as #thebadbad suggested

 

#2: Just treat the image with lowest number as 1st and so forth. If the user selects image2, image4 and image6 translate that into image1, image2, image3 and give a f**k about what the user thought he or she did.

 

#3: Do some validation with PHP and if they did not comply with your standards throw an error.

Would it make sense to use this?

 


if(isset($_POST['image1'])){$image1set = TRUE;}

 if((isset($_POST['image2'])) && (!isset($image1set))){$image1error = "You must upload a main image in the image 1 field!";$error=1;}
 if((isset($_POST['image3'])) && (!isset($image1set))){$image1error = "You must upload a main image in the image 1 field!";$error=1;}
 if((isset($_POST['image4'])) && (!isset($image1set))){$image1error = "You must upload a main image in the image 1 field!";$error=1;}
 if((isset($_POST['image5'])) && (!isset($image1set))){$image1error = "You must upload a main image in the image 1 field!";$error=1;}
 if((isset($_POST['image6'])) && (!isset($image1set))){$image1error = "You must upload a main image in the image 1 field!";$error=1;}


I haven't come up with the prettiest method of verifying this with PHP but I'm working on it :)

 

Personally I would like to do this with PHP instead of JavaScript since javascript can be disabled making the application non-functional.

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.