Hello, in a form I use custom form validation using the cred_form_validate hook (they are simple validations, most of the essential fields are not empty and I need a field in a very specific format)
Everything works fine, but I'm having problems with the post title field, which by default has its own native validation that I can't disable. In this way, if someone does not enter any data in the form, the error of no title only occurs first (custom validations are not executed). Custom validations run without a problem when the user has already entered the post title
I understand that it is very rare for someone to skip that field, but I would like to manage all validations in the cred_form_validate hook for maximum consistency
The cred_form_validate hook works on the server, when the form has been passed from the browser.
In this case I would be inclined to add some JavaScript (or jQuery) to pre-validate the form to ensure the post title field is populated before proceeding to submit the form.
Can you please try to follow what Nigel described by adding custom jQuery to add dummy value to post title field and check if that help you to resolve your issue.
var submitButton = document.getElementById('cred_form_12869_1_1_form_submit_1');
var titleInput = document.getElementById('cred_form_12869_1_1_post_title');
// titleInput.value = ''; Whe the page load, this could help me empty the field, so that the user doesn't see the dummy value. But for now I'll mention it first I want to make it work
I manage to go to validation with the field empty. BUT, for some reason I can't get the post title to be evaluated in the personality validation, I don't see the problem
$titulo_anuncio_campo = 'wpv-post-title';
if (isset($fields[$titulo_anuncio_campo]) && $fields[$titulo_anuncio_campo]['value'] === '###') {
$errors[$titulo_anuncio_campo] = 'Por favor coloca nombre al anuncio';
}
I think I found the problem, what happened is that I was thinking too much about Toolset, the variable to check in this case is not 'wpv-post-title', in this case 'post_title' should be checked
Please don't close the topic yet, I'm doing more testing before putting this on the real page
Popular the "post title" field is a valid option, but it generates other inconveniences. Mainly, the "dummy" data can be visible or the other way around, one may empty the field involuntarily. I think that with a little patience and logic, a balance can be found so that it does not bother the user
But finally I opted for another path, simply create a new custom field, which in the cred_save_data hook overwrites the post_title. So far it's fine and since that hook does so many things in my project I maintain greater consistency