I have a CRED post form which has several custom fields on it. Some of the custom field definitions do not require the fields to have values. However, in the CRED form we want to require the fields to have values. Can I write some custom JavaScript to validate the data? If so, how?
I tried to use jQuery to intervene in the submission process, but this test code did not work:
jQuery('#cred_form_5814_1_1_form_submit_1').on('submit',function (event) {
event.preventDefault();
console.log('cred form has been submitted');
return false ;
} ) ;
I applied the code and it worked great, for the most part. I tried to use the code for the Post Body field, and I encountered two issues:
+ Clicking the Submit button is supposed to jump the visitor to the first field that's required and is empty. This doesn't happen with the Post Body field. Clicking Submit doesn't move the user anywhere.
+ After clicking Submit, any empty fields that are required display an error message. Typing in those fields makes the message disappear. When entering some information into the Post Body field, the error message remains visible.
Another thing I discovered is that this code does not work for custom taxonomies. Do you know how I can test whether one taxonomy item has been selected?
Lastly, I needed to wrap the if statement in another if statement to prevent array undefined index PHP notices:
The thing is that post body field will be validated on server side if you use the Toolset Form's validation hook. You can not hook the required field validation for the post body field as it's a different kind of field i.e. WYSIWYG.
Thanks for your reply, Minesh. I'll validate the post content field via the cred_form_validate hook per your suggestion.
Another thing I discovered is that the code snippet you provided does not work for custom taxonomies. Do you know how I can test whether one taxonomy item has been selected *before* the form has been submitted? Is there a JavaScript event I can interrupt? The jQuery I attempted to use in the first message in this thread did not work.