[Resolved] Validating "Please select …" option using cred_validate_form
This support ticket is created 7 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
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.
Like him, I want to have a "Please select a service" at the top of the SELECT list. If the user does not select one of the items, he should get a "Please select service" error.
I tried the proposed solution but couldn't get it to work. Here is screenshot that hopefully will give you the details that you need.
Note: The instructions I followed state that I should NOT use wpcf- prefix. Somewhere else on your site I thought I read that I should but I can't seem to find it now.
Thanks Shane but result is same. I beginning to wonder if the function is even firing.
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==58)
{
//check my_field value
if ($fields['wpcf-services-required']['value']=='0')
{
//set error message for my_field
$errors['wpcf-services-required']='Please select a service';
}
}
//return result
return array($fields,$errors);
}
I would like for you to try a few more things for me 🙂
Firstly This could be caused by a plugin conflict and stopping the validation from functioning.
What I could recommend that you do is to temporarily disable all your non-toolset plugins and try the form again.
Additionally I would like to see what environment your website is running on. For this I would like for you to provide me with the debug information on your website.
Just to be clear: My CRED form exists inside a widget on the home page of a Genesis theme..
Your request => "temporarily disable all your non-toolset plugins and try the form again."
When I did this, the CRED form disappears from the home page. Take a look at the screen shot. Viewing the page source via Chrome DevTools, you'll see the shortcode text and not the CRED form. The only way that I was able to get the CRED form back on the home page was to deactivate the CRED plugin, then reactivate the WP SVG ICONS plugin followed by reactivating the CRED plugin. The WP SVG ICONS plugin is inserted into another widget on the home page. So it doesn't look like they are playing nice together. For some reason the WP SVG ICONS plugin needs to be activated first. But ultimately that is not related to my original problem and I can prove it.
I created another WordPress site on my desktop with a smaller version of the CRED form (and yes wpcf-services-required is now just wpcf-services - That is reflected in the php code). Only installed Toolset plugins, nothing else. Same result. See screenshot. On one attempt, I even added a wp_die('Whoops!') call, as the 1st line in the my_validation function, just to see what would happen. Again same result. The cred_validate_form filter just doesn't seem to be executing my_validation function.
Now it seems that we have two issuess (original and WP SVG Icon compatibility).
BTW, I did supply the debug info in the above box. But in edit mode, it seems to have disappeared. I can resend if need be.
Fixed the original "Please Select a Service" problem by simply removing the value (i.e. 0) from the "Please select one:". See screenshot. Now it works fine. I should have realized this from the beginning. I don't know what I was thinking.
I have to admit that I am disappointed with Toolset for forum solutions that are not only misleading but simply dead wrong. There is no need to use the cred_form_validate filter. The one I referred to above should either be updated or removed.
I left my status at "Still need assistance" since I wanted to make sure that you saw my previous post.
I assume that nothing will be done about the WP SVG Icons compatibility issue.