Skip Navigation

[Resolved] Let the user choose an image or upload one, but not both.

This thread is resolved. Here is a description of the problem and solution.

Problem:
I have a CRED Form with Image Fields where users choose a background image among those preloaded or upload their own image if the preloaded one does not like.

I've created a new "image" field, but I do not understand how to make the user do one thing only: either they choose or upload.

Solution:
https://toolset.com/forums/topic/custom-fields-choose-or-upload-image/#post-614843

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.45 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#614789

I have a module CRED (field-radio) where users choose a background image among those preloaded or upload their own image if the preloaded one does not like.

I've created a new "image" field, but I do not understand how to make the user ONE one thing: either they choose or upload.

thank you

#614843

There can be several approaches to this goal.

Mainly, what you need is a method to decide what the user did, and accordingly hide or show the correct inputs on the form.

The easiest way to achieve this is by using CRED Conditional Groups.
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/

You can for example add a generic "Checkbox" Field - let's name it "upload_or_choose" with label "You do not like the images? Upoload my own!".
If this Checkbox is checked, you would hide the Upload Field, if it's not checked, you show the upload field but no existing images field.

The user will initially see the Checkbox unchecked, and only the image you provide him.
Then, if he does not like them, he can check the box and the upload field will appear.

A code sample to use in a CRED Form (please insert this with the GUI, according the DOC, not by copy paste):

[cred_generic_field field='upload_or_choose' type='checkbox' class='' urlparam='']
{
"required":0,
"validate_format":0,
"checked":0,
"default":"1",
"label":"You do not like the images? Upoload my own!"
}
[/cred_generic_field]

[cred_show_group if="($(upload_or_choose) ne  '1' )"  mode='fade-slide']
This here will display your images you already offer to the user
[/cred_show_group]

[cred_show_group if="($(upload_or_choose) eq  '1' )"  mode='fade-slide']
This here will display the Upload Field
[/cred_show_group]

Now the user will see the Form with a set of images as you provide him.
If he doesn't like it, he can check the Checkbox and an upload field appears, while the images you provide disappear.

Sorry that I use only one gender here, it's easier to just say "he, him, it, etc" - I think it's about the technical aspect mainly right 🙂

Please let me know if you can achieve the goal with this information.

Thank you.