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