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

Minesh
Supporter

Languages: English (English )

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

The featured image is already set as required field now. If you will not upload the featured image, it will ask you to upload.

We recommend to use the Media Library to upload the images.

Please check the following video: hidden link

#1996579
Upload.JPG

This is the result I need.
But I can't use the "Media Library" option because this site is a social and you don't have to see the images upload to the WordPress library but the user has to upload the image as shown in the screenshot the attachment

#1996589

Minesh
Supporter

Languages: English (English )

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

Ok - I've added the following code that will force the featured image as required field.

I've also set your form to not use "Media library".

add_filter('cred_filter_field_before_add_to_form', 'required_fields_func', 10, 1);
function required_fields_func($field){
    //error_log(print_r($field, true));
    if(in_array($field['id'], array('_featured_image'))){
        // in some cases $fields['data'] is an empty string, so you'll need to first set it's expected format for PHP 7.1 compatibility
        if (!is_array($field['data'])) {
            $field['data'] = array();
        }
        $field['data']['validate']['required'] = array ( 
            'active' => 1,
            'message' => 'This field is required'
        ) ;
 
         
    }
    return $field;
}
#1996595

My issue is resolved now. Thank you!