Skip Navigation

[Resolved] Validate Values on User Form

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to create a custom validation for their form.

Solution:

To create a custom validation I would recommend having a look at our API document below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created 5 years, 10 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.

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

Last updated by julieP 5 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1191137

When users registers I'd like them to enter an email address that they'll use to sign in (user_email) and a second email address which is a custom user field (wpcf-alt-email). I'd like to be able to validate the form on submission to ensure that the two email addresses are different.

I've tried this without success

add_filter('cred_form_validate','ts_validate_emails_493',10,2);
function ts_validate_emails_493 ( $field_data, $form_data ){
    
    if ($form_data['id']==493)    {
        
        list($fields,$errors)=$field_data;
        
        if ( $_POST ['wpcf-alt-email'] == ['user_email'] ) {
            $errors[] = 'Your email addresses are the same; please change one';
        }
    }
    return array($fields,$errors);
}

Any ideas please? Thank you!

#1191270

Shane
Supporter

Languages: English (English )

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

Hi Julie,

Thank you for contacting our support forum.

This method should work fine.

        if ( $fields['wpcf-alt-email'] ['value']== $fields['user_email']['value'] ) {

Changing your conditional statement to this should resolve the issue.

Thanks,
Shane

#1191897

Ah yes - thank you - I can see where I went wrong now!