Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 6 replies, has 3 voices.

Last updated by benjaminJ-3 7 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#495313

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.

Thanks

#495685

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Steve

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.

#496622

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Steve

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.

#497948

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.)

add_filter('cred_filter_field_before_add_to_form', 'my_plugin_modify_form', 10, 2);
function my_plugin_modify_form($field, $computed_values) {
	if ( !empty($_POST) ) {
		return;
	}
	
	switch ( $computed_values['type'] ) {
	case 'wysiwyg':
		
		$field['data']['validate'] = array(
			'required' => array(
				'active' => 1,
				'value' => 1,
				'message' => $field['name'] . ' is required',
			)
		);
		
		break;
	}
	return $field;
}

The check on $_POST is there is because I was getting unexpected errors on form submission

#499561

Update to code I posted.

    if ( !empty($_POST) ) {
        return;
    }

needs to be

    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;
    }
#1989177

Is this ever going to get added to Toolset? I'm sure it's a popular feature.

#1998043

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.