Skip Navigation

[Resolved] Custom verification form and "post title" field

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
- 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 4 replies, has 3 voices.

Last updated by hernanL 5 months ago.

Assisted by: Minesh.

Author
Posts
#2703364

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

What I can do?

Thanks greetings

#2703464

Nigel
Supporter

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

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

Hi there

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.

#2703471

Minesh
Supporter

Languages: English (English )

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

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.

#2703555

I was able to populate that field with js with something similar to this:

document.addEventListener('DOMContentLoaded', function() {

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

submitButton.addEventListener('click', function() {

if (titleInput.value.trim() === '') {

titleInput.value = '###';
}

});
});

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

#2703562

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

#2703592

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

Thanks for the support and advice