Skip Navigation

[Resolved] Why no option for "required" in CRED WYSIWYG field?

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

Last updated by benjaminJ-3 5 years ago.

Assisted by: Minesh.

Author
Posts
#1388455

Tell us what you are trying to do?
I want to make a WYSIWYG field in a CRED form "required".
That does not appear to be an option.
Why not?

#1388529

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Actually - post_content field is not required by WordPress and that is why with Toolset form that field is not required.

If you want to make post_content field required, you should try to use the Toolset Form's hook: cred_form_validate
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

For example:

add_filter('cred_form_validate','func_validate_post_body_field',10,2);
function func_validate_post_body_field($field_data, $form_data) {
    //field data are field values and errors
    list($fields,$errors)=$field_data;
   
    
    if ( empty($fields['post_content']['value']) )  {
        //set error message for post_content field
        $errors['post_content']='Please enter post content.';
    }   
  
    //return result
    return array($fields,$errors);
}

And, another workaround would be, you should remove the post_content field from your form and add a Generic field instead.
For example:

[cred_generic_field field="post_content" type="textarea"  class="" urlparam=""]
{
"required":1,
"validate_format":0,
"persist":0,
"default":""
}
[/cred_generic_field]

More info:
=> https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

#1388963

Thanks, Minesh. I have been working with Toolset Types/Views for over 5 years now, and still have not dived into the workings of the cred_form_validate hook. I have previously taken a few quick looks at it but, I didn't have time to go further. Thanks for posting your examples; that should be a very good start for me to finally figure this out.

Yesterday, I was thinking of changing the field type from WYSIWYG to textarea, but I noticed you cannot quickly change from the WYSIWYG type to another field type. So, I think I would need to create a new field with type textarea and name it the same as the WYSIWYG field. I have 5 years history of events with slides and video I need to keep.

I originally thought I should give the job/project poster the WYSIWYG capability, but in reality, it's just not necessary. So, I will switch to a textarea.

==>> But, I still wonder why I need to use a generic field for that. Why can't I just create a normal textarea field? Is that also not able to set as "required"?

Thanks, Minesh. And have a good day/evening/whatever...
Jeff Safire
-------------------

#1389203

Minesh
Supporter

Languages: English (English )

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

Thanks, Minesh. I have been working with Toolset Types/Views for over 5 years now, and still have not dived into the workings of the cred_form_validate hook. I have previously taken a few quick looks at it but, I didn't have time to go further. Thanks for posting your examples; that should be a very good start for me to finally figure this out.
==>
Great.

Yesterday, I was thinking of changing the field type from WYSIWYG to textarea, but I noticed you cannot quickly change from the WYSIWYG type to another field type.
==>
Yes, this is true and its a limitation.

So, I think I would need to create a new field with type textarea and name it the same as the WYSIWYG field. I have 5 years history of events with slides and videos I need to keep.
==>
Ok.

But, I still wonder why I need to use a generic field for that. Why can't I just create a normal textarea field? Is that also not able to set as "required"?
==>
if you will create textarea field with your custom field group, it will be a custom field and the value for that will be stored in the post meta table if you add that textarea field to your form and will not affect the post_content field.

So, if you just want to keep the post body (post_content) field in admin but want to display textarea instead of WYSIWYG field that belongs to (post_content) field, you should just create a generic field using the textarea and make it required and give the same name as (post_content) so it will save the value to post body (post_content) field.

Actually, its your choice what you want and how you want to save content.

#1391891

Well, some of that context is a bit confusing to me at the moment. I will have to take a look and try what you suggest in order to better understand what this means. It does appear to have a solution for me, but I prefer to keep this thread open at the moment until I try this myself.

Thanks
Jeff Safire
––––––––––

#1392057

Minesh
Supporter

Languages: English (English )

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

Sure - just changing the ticket status. Please feel free to get in touch with me if you need further assistance regarding your query.

#1998037

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);
}

#1998045

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);
}