The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Limit Number Entries Based on Value in Another Field

Labels

This Discussion is public

Notifications

I have an order form on which the total number of "widgets" a user is ordering is calculated in a field (Field 25). In a separate field (Field 26), the user is asked how many of the widgets require some premium upgrade. Based on the values in Field 25 and Field 26, a total price can be calculated.

Logically, you can't upgrade widgets that don't exist. How can I validate that the value entered in Field 26 is never greater than the calculated value in Field 25.

Note: I realize that I could have the user make multiple selections throughout the form (widgets with upgrades in one field and widgets without upgrades in another). However, I prefer not to go this route due to certain design considerations.

You can do this with jQuery if you want to validate the premium field in real time before the form is submitted, otherwise you can do it in PHP if you want to tie into Formidable's server-side validation. The PHP executed after the form is submitted but before it's saved to the database.

A very simple script that can get the job done would look like:


jQuery(document).ready(function ($) {
"use strict";

$("#field_bcde").on('change', function() {

var valid_amt1 = $('#field_abcd').val(),
valid_amt2 = $('#field_bcde').val();

if( valid_amt2 > valid_amt1 ) {
alert('Field 26 cannot be greater than Field 25');
$('#field_bcde').val(valid_amt1);
}

});

});

You would need to substitute your own language and field ids.

Discussion closed.