Skip Navigation

[Resolved] Form Validation Message Will Not Show

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

Last updated by Minesh 1 year, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2651299

I am trying to: use cred_form_validate to show an error message

Link to a page where the issue can be seen: private access

I expected to see: a message under the form field that Says: Book titles must be unique.

Instead, I got: The form does not submit as expected but there is no notification to the user as to why.

If I var_dump $returndata I can see my error message showing up but there is no text under the field explaining why the form was not submitted. However if I leave the field completely blank I do get a notice that it cannot be empty. It's just when the cred_form_validate hook fires I don't get that message if the post already exists.

In short, the first part works (form does not submit if title is not unique), but the part with the notice is not coming up.

add_filter('cred_form_validate_114', 'validate_post_title', 10, 2);

function validate_post_title($error_fields, $form_data) {
list($fields, $errors) = $error_fields;

// Get the post title.
$post_title = $fields['post_title']['value'];

// Check if the post title is unique.
$query = new WP_Query([
'post_type' => $form_data['post_type'],
'post_title' => $post_title,
]);

if ($query->have_posts()) {
// The post title is not unique.
$errors['post_title']='Book titles must be unique.';

}
$returndata = array($fields, $errors);
return $returndata;
}

#2651411

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

What if you try to use the following code and try to resolve your issue:

add_filter('cred_form_validate','validate_post_title',10,2);
function validate_post_title($error_fields, $form_data){
//field data are field values and errors
list($fields,$errors)=$error_fields;


// get the title from the form
 $post_title = $_POST['post_title'];
		
//validate if specific form
if ($form_data['id'] == 114 ) {
	
$post_exists = get_posts([
'post_type' => $form_data['post_type'],
'name' => $post_title,
'numberposts' => 1
]);

		//check my_field value
		if (count($post_exists) > 0) {
			//set error message for my_field
			$errors['post_title']='Book titles must be unique.';
		
		}

}
//return result
return array($fields,$errors);
}
#2651471

Hello, that produces the exact same results. Stops the form from completing but does not give the user an error message as to what is wrong.

#2651503

Minesh
Supporter

Languages: English (English )

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

Can you please share problem URL where I can see the form as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2651543

I can't make a backup of this site, it's too large. I built a work around using jQuery and echoing out a div when the validation fails.