Skip Navigation

[Resolved] fornt-end form with featured image request

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

Problem:
fornt-end form with featured image request - set featured image required.

Solution:
You can use the Toolset Form's hook "cred_filter_field_before_add_to_form" to set featured image as the required field.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/fornt-end-form-with-featured-image-request/page/2/#post-1996589

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

This support ticket is created 3 years, 8 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 3.65 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 18 replies, has 2 voices.

Last updated by zenariM 3 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1991899

Hi,
I need to set the featured image as obligatory field in my fornt-end form.
How can I set this?

Thanks for the support

#1991991

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the Toolset Form's hook "cred_form_validate":
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

For example - add the following hook to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter('cred_form_validate','func_validate_featured_image',10,2);
function func_validate_featured_image($error_fields, $form_data) {
    //field data are field values and errors
    list($fields,$errors)=$error_fields;
    //uncomment this if you want to print the field values
    
    if ($form_data['id']==9999) {
       
        if (empty($fields['_featured_image']['value'])){
            //set error message for featured image
            $errors['_featured_image'] = 'Missing featured image';
        }
    }
    //return result
    return array($fields,$errors);
}

where:
- Replace 9999 with your original form ID

#1992437
Error.JPG

Hi, I tried the code and it works for the "featured image" but it gives me problems in the gallery field above.

#1992999

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please clarify what exactly the problem you having with your image repeating field?

#1993197
Error.JPG

I have a front-end form for inserting a post in my custom post type created with Toolset.
I want to force the user to put the "featured image" and also the gallery photos.
With the code you gave me, this error occurs in the gallery field when I try to submit the form (see attachment).
The problem in the gallery is that I duplicate the images and it presents me with the following errors that are in the attachment.

Could you help me make the "featured image" mandatory?
Thanks so much

#1993353

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where I can see the issue as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1995701

I have sent all the necessary data.
I remain available for anything.
Thanks again for the support.

#1996035

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

thank you for sharing access details.

Can you please tell me what is the issue with gallery image. Do you also want to validate the gallery image as well? Do you want to make required Gallery images field?

#1996337
1993197-Error.jpg

The gallery works fine as it is now set up on the site and the gallery field control works as well.
The problem was that, by entering the code you gave me, the check on the "featured image" went however the gallery fields got bugged and this error came out even if I hadn't put any image in the gallery field (see attachment for the error).

What I would need is to make the "featured image" field mandatory and that everything else in the form works correctly

Thanks again for the support

I remain available for anything.

#1996373
199sd3197-Error.jpg

The gallery works fine as it is now set up on the site and the gallery field control works as well.
The problem was that, by entering the code you gave me, the check on the "featured image" went however the gallery fields got bugged and this error came out even if I hadn't put any image in the gallery field (see attachment for the error) .

What I would need is to make the "featured image" field mandatory and that everything else in the form works correctly .

Thanks again for the support

I remain available for anything.

#1996503

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

On your form: hidden link

I've activated the setting "Use the WordPress Media Library manager for image, video, audio, or file fields". So that it will allow you to upload the images using Media library.

Now, can you please check it works as expected.

#1996515

Sorry, maybe I explained myself badly.
I don't need the "Use the WordPress Media Library manager for image, video, audio, or file fields" feature because users don't need to see the "WordPress Media Library" images.

What I would like is that that form necessarily requires the "featured image" to submit the form.

#1996519

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Your featured image is required only. The only difference is you will be allowed to upload image using media library.

#1996535
Immagine.JPG

I need to set this field as required (this field is the "featured image" field).
I was fine with the old image upload setup.

#1996551
Required.JPG

I sent the form and in this field the message "This field is required" did not come out because this field "featured image" is not set as mandatory and I would like the "featured image" field to be mandatory (but with the same method of upload that was there before)