Skip Navigation

[Resolved] CRED Form – Limit number field number

This support ticket is created 3 years, 4 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
- 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 1 reply, has 2 voices.

Last updated by Minesh 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2108397

Hi

Is it possibly to limit a number field value to say 99?

So for example if someone enters a value above 99 then it just sets the value to 99 when the form is saved? So it doesn't let the value be above this?

Thanks

#2108451

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes, its possible using the Toolset form's hook: cred_before_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

For example:

add_action('cred_before_save_data', 'func_check_and_adjust_number',10,1);
function func_check_and_adjust_number($form_data) {
    // if a specific form
    if ($form_data['id']==99999) {
        if (isset($_POST['field-slug']) and  $_POST['field-slug']>100) {
            $_POST['field-slug'] = 99;
        }
    }
}

Where:
- Replace 99999 with your original form ID.
- you should adjust the code as required

So, you should check the field value before its get saved to database and adjust it as per your requirement.