Skip Navigation

[Resolved] How to do simple validation

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

Problem:
How to validate CRED form server side.

Solution:
CRED offers validation hook: "cred_form_validate" using which you can validate your CRED form at server side.

You can find proposed solution on the following link:
=> https://toolset.com/forums/topic/how-to-do-simple-validation/#post-379193

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-api/#cfv

This support ticket is created 8 years 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
- 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 7 replies, has 2 voices.

Last updated by pamelaB-2 7 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#375723

I have a simple numeric field and I just want to have users enter 13 digits, no more and no less.

How is this done? I seem to remember some time ago that types had a validation setting when creating custom fields, and we could use regex.

#375742

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please let me know where you want to apply this validation -at front section using CRED form?

Could you please tell me more details about your setup so that I'll be able to guide you in right direction.

#376281
id-field.JPG

Hi Minesh.

The field is a types user field, and it is displayed on user registration (as well as user edit) CRED frontend forms.

I want to apply this validation when the user submits either form on the front end.

Numeric field, I need to capture user ID number which should be 13 numeric characters long.

#376347

Minesh
Supporter

Languages: English (English )

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

CRED offers validation hook: "cred_form_validate" using which you can validate your CRED form.

More info:
https://toolset.com/documentation/user-guides/cred-api/#cfv

#376769

So what you're saying is that I need to be a PHP developer in order to do simple validation on CRED fields?

#377097

Minesh
Supporter

Languages: English (English )

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

You may refer to hook with example that will guide you how to apply validation.

Or

You can send me problem URL with test data you want to validate and I'll try to fix your issue.

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#379193

Minesh
Supporter

Languages: English (English )

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

I've added following code to your custom.php file:

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;
    
    //validate if specific form
    if ($form_data['id']==283)
    {
	        //check my_field value
        if (strlen(trim($fields['wpcf-id-number']['value'])) != 13 )
        {
            //set error message for my_field
            $errors['wpcf-id-number']='Please enter exact 13 digits';
        }
 
    }
	 
    //return result
    return array($fields,$errors);
}

Now the field is validated for exact 13 characters.

I hope above solution will help you to resolve your issue.

#379402

Thank you.

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