Skip Navigation

[Resolved] How to change Rich text editor (WYSIWYG) to a plain text editor

This thread is resolved. Here is a description of the problem and solution.

Problem:
It is not possible to disable the Wysiwyg controls on the post body added to a CRED form. The client wants to replace it with a multiline text field, and then when the form is submitted update the actual post body with the contents from the multiline text field.

Solution:
Add a generic multiline text field to your CRED form, e.g. with a slug of false-body. Then add the following code to your theme's functions.php file (or using a plugin such as Code Snippets), editing the form id as required.

function tssupp_false_body( $post_id, $form_data ){
 
    if ( $form_data['id'] == 99 ) { // Edit
 
        $false_body = $_POST['false-body'];
 
        if ( $false_body ) {
 
            $args = array(
                'ID'            =>   $post_id,
                'post_content'  =>   $false_body
            );
 
            wp_update_post( $args );
        }
    }
}
add_action( 'cred_save_data', 'tssupp_false_body', 10, 2 );
This support ticket is created 5 years, 11 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
- 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+00:00)

This topic contains 9 replies, has 2 voices.

Last updated by leilaG 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#652167

As requested separating questions into separate tickets -

1. How to change Rich text editor (WYSIWYG) to a plain text editor
There is no way to change the main post body input to restrict WYSIWYG capabilities, but you could remove the post body field and replace it with a multiline custom field. No WYSIWYG features are included in a multiline custom field.

Okay, how do I ensure the multi line custom field content is inserted into the main body of the post?

#652497

Nigel
Supporter

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

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

Hi Leila

You would need to do that with some custom code that uses the cred_save_data hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Use a generic multiline text field in your form rather than creating a Types multiline field, in which case the field will be submitted with the form but won't itself be stored in the database.

Your code will take the contents of that field and then immediately update the body of the newly created post, using wp_update_posts (https://codex.wordpress.org/Function_Reference/wp_update_post).

The generic field will itself be discarded.

Are you able to write that yourself or do you need some help?

#655732

Thank you for the information, yes please I would like some help.

#656050

Nigel
Supporter

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

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

Hi Leila

You would need to add code such as the following to your theme's functions.php file (or using a plugin such as Code Snippets):

function tssupp_false_body( $post_id, $form_data ){

	if ( $form_data['id'] == 99 ) { // Edit

		$false_body = $_POST['false-body'];

		if ( $false_body ) {

			$args = array(
				'ID'			=>	$post_id,
				'post_content'	=>	$false_body
			);

			wp_update_post( $args );
		}
	}
}
add_action( 'cred_save_data', 'tssupp_false_body', 10, 2 );

You would need to edit the ID of the CRED form in question.

#656522

Thank you for the code, could you please highlight where exactly I need to add the Form ID

Also do I need to add multiline text field name into the code?

#656533

Nigel
Supporter

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

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

Hi Leila

The form ID in my sample code is 99, that's what you need to update.

And you are right, I forgot to mention editing the generic multiline field name.

In my example it is "false-body", so you would edit the $_POST['false-body']; part of the fifth line above.

#657557

Okay the code has been updated, but it's not working

functions.php -

function tssupp_false_body( $post_id, $form_data ){

if ( $form_data['ID'] == 17097 ) { // Edit

$false_body = $_POST['Description'];

if ( $false_body ) {

$args = array(
'ID' => $post_id,
'post_content' => $false_body
);

wp_update_post( $args );
}
}
}
add_action( 'cred_save_data', 'tssupp_false_body', 10, 2 );

cred form -

<label>Company Description</label>
[cred_generic_field field='Description' type='textarea' class='form-control' urlparam='']
{
"required":1,
"validate_format":0,
"default":""
}
[/cred_generic_field]

#671868

Nigel
Supporter

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

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

You have used capitals for ID in $form_data['ID']. It should be lower case, i.e. $form_data['id']

#678808

Amazing!! Thank you for your help ?

#752990

Hello Again,

How do I use the below function for more than one form?

function tssupp_false_body( $post_id, $form_data ){

if ( $form_data['id'] == 17097 ) { // Edit

$false_body = $_POST['Description'];

if ( $false_body ) {

$args = array(
'ID' => $post_id,
'post_content' => $false_body
);

wp_update_post( $args );
}
}
}
add_action( 'cred_save_data', 'tssupp_false_body', 10, 2 );

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.