[Resolved] Add ability to set WYSIWYG field to required
This support ticket is created 7 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
While there is this https://toolset.com/forums/topic/how-to-make-required-a-wysiwyg-custom-field-with-types/, the response is unsatisfactory. It never explains why it is "by design" not possible to set WYSIWYG fields to required. While multiple line inputs do support it, users often want a WYSIWYG editor and it would seem simple to add the ability to set a WYSIWYG field as required.
As an alternative, the CRED plugin short cred_field supports setting the field to required but does not allowing setting the message, adding the ability to set the message would also work.
Firstly, let me apologise for the slow response. We have an automated system for distributing tickets between supporters and it has been mis-behaving today. I spotted how old your ticket was and so have taken it.
I checked with our developers and there is no technical reason why a WYSIWYG field cannot be required, I'm not sure why it currently is not possible.
We'll bring this up with developers at the daily meeting tomorrow and get back to you.
Just to confirm that the developers accepted this as a feature request, there being no technical reason for not letting WYSIWYG fields be marked as required, and so it should make it into an upcoming release of Types.
I can't give any indication yet of which, or when it will be released, though.
Whenever a Types update is published, be sure to read the changelog.
For anyone reading this thread, before the feature added you can use the following
(You will want to change 'my_plugin' to reflect your plugin or theme.)
if ( !empty($_POST) && !empty($_POST['post_title']) ) {
// We do not want to make modifications when the post is submitted
// So we return if $_POST is set and there is a post title
// Checking for post title catches the user doing a page refresh while on the form page
return $field;
}
The solution in this thread did not work for me but this does (you need to do this for each wysiwyg field slug):
//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-wyswyg-slug']['value'])) {
$errors['wpcf-wyswyg-slug'] = 'Missing wyswyg';
}
return array($fields,$errors);
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.