Skip Navigation

[Closed] wysiwyg required

This support ticket is created 4 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 3 voices.

Last updated by Waqar 4 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2106129

I found this post
https://toolset.com/forums/topic/add-ability-to-set-wysiwyg-field-to-required/

I have a wysiwyg custom field and need it to be required.
How do I do this?

#2106191

Hello,

There isn't such kind of built-in feature, I assume we are talking about a WYSIWYG field in Toolset post form, you can try the cred_form_validate filter hook like this:
Add below codes into your theme file "functions.php":

//Text-like fields (textarea, WYSIWYG) have only one value, which is the actual input text.
add_filter('cred_form_validate', 'validate_form_wyswyg');
function validate_form_wyswyg( $data ) {
    list($fields,$errors)=$data;        
    if (empty($fields['wpcf-my-wyswyg-slug']['value'])) {
        $errors['wpcf-my-wyswyg-slug'] = 'Missing wyswyg';
    }
    return array($fields,$errors);
}

Please replace "my-wyswyg-slug" with your custom WYSIWYG field slug

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
This hook provides custom validation for form fields.

#2111161

copied and pasted this
//Text-like fields (textarea, WYSIWYG) have only one value, which is the actual input text.
add_filter('cred_form_validate', 'validate_form_wyswyg');
function validate_form_wyswyg( $data ) {
list($fields,$errors)=$data;
if (empty($fields['wpcf-scope-of-work']['value'])) {
$errors['wpcf-scope-of-work'] = 'Missing wyswyg';
}
return array($fields,$errors);
}

And got this error

Your PHP code changes were rolled back due to an error on line 11 of file wp-content/toolset-customizations/wysiwyg.php. Please fix and try saving again.

Cannot redeclare validate_form_wyswyg() (previously declared in wp-content/themes/Avada-Child-Theme/functions.php:16)

Line 16 is.......function validate_form_wyswyg( $data ) {

#2111787

My mistake. Fixed function.php. It was accepted but nothing seems to happen.

1-Paste code to function.php
2-replace "my-wyswyg-slug" with my custom slug "wpcf-scope-of-work"

And should work, correct?

#2112993

Hi,

Thanks for writing back.

Luo is on vacation so I'll be following up on this ticket.

I've tested the following code on my test website with a field with slug "scope-of-work" and it worked as expected. The error message showed when the form was submitted:


add_filter('cred_form_validate', 'validate_form_wyswyg');
function validate_form_wyswyg( $data ) {
    list($fields,$errors)=$data;        
    if (empty($fields['wpcf-scope-of-work']['value'])) {
        $errors['wpcf-scope-of-work'] = 'Missing wyswyg';
    }
    return array($fields,$errors);
}

Can you please check the code again and make sure that you've used the field's slug correctly?

In case the issue still persists, you're welcome to share temporary admin login details along with the link to the page where this form can be seen.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

The topic ‘[Closed] wysiwyg required’ is closed to new replies.