Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Geoffrey 7 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#414537
Cred_form_validate.png

I have a problem similar to the following post except my user is only selecting one of 4 services (i.e. not one of 50 states).

https://toolset.com/forums/topic/need-logic-to-validate-an-entry-in-a-select-field-in-cred-form/

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 for any help.

#414559

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoffrey,

Thank you for contacting our support forum.

Could you try using wpcf-services-required in your hook instead of just services-required.

Please let me know if this helps.
Thanks,
Shane

#414564

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);
}
#414631

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoffrey,

Thank you for trying this for me.

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.

To do this please follow the instructions in the link below.
https://toolset.com/faq/provide-debug-information-faster-support/

Looking forward to hearing from you.
Thanks,
Shane

#414702
Cred_form_validate_2.png

Hi Shane,

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.

#414706
Cred_form_validate_3.png

Hi Shane,

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.

#415147

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoffrey,

Would mind providing me with admin access to the website so I can have a look ?

The private fields will be enabled for your next response.
Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.