Skip Navigation

[Resolved] Making the default post content field required

This support ticket is created 5 years, 7 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.

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 4 replies, has 2 voices.

Last updated by Minesh 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1252885

Hi, I am trying to make the default WYSIWYG post field a required field. I know I could just create a new WYSIWYG field and add this but I have lots and lots of already filled in posts with information in the existing field.
Many thanks in advance.

#1252927

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - there is no JS solution to make the field required but you can use the Toolset Form's validation hook cred_form_validate to validate your form for the post content field on the server side.

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#1253059

Hi Minesh, thank you for your response. Would you be able to help me with the code needed to implement this?

#1253821

Minesh
Supporter

Languages: English (English )

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

Sure. Can you please share problem URL where you added the form as well as access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#1255095

Minesh
Supporter

Languages: English (English )

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

Well - I've added the following code to Toolset's Custom Code section "toolset-validate-form ":
=> hidden link

add_filter('cred_form_validate','func_validate_post_content',10,2);
function func_validate_post_content($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
    //print_r($fields);
    //validate if specific form
    if ($form_data['id']==487){
        //check my_field value
        if ($_POST['post_content']==''){
            //set error message for my_field
            $errors['post_content']='Empty post conent.';
        }
       
    }
    //return result
    return array($fields,$errors);
}