Question for a utility

Greetings everyone,

I’d like to know if it is possible to do this:

I have two Number Fields Named Product ID & Product Serial Number

Product ID should have 79 different numbers stored somewhere. The same goes for Product Serial Number as well. Notice though that the pool of numbers are different for each field.

On form submit each of the above fields must make a validation. That means each field to be able to search the value that the user has typed and make a check if that number exists in the pool.

If yes the form submits successfuly and in the meanwhile the Product ID & Product Serial Number entered and matched from the pull gets erased / can’t be used again in a new form submition.

If the number of each field the user has entered is erased from a previous form submition the user should get notified that the typed numbers are invalid.

Is it possible to create this logic using gravity forms?

*P.S In the meanwhile I created a table in my database and added the values I need for validation. Seems for a reason with anything I tried so far that on submit can’t handle the data of the database table.

If you’re looking for a quick solution that is less elegant you could hook into gform_validation and use that to check if the value entered by the user is an existing product ID or serial number.

Since you don’t want a duplicate for a combination of two fields, I would combine both fields into one as a quick fix. I would create a string field with an input mask that allows an entry like “product_id-product_serial_number”. Then, using the hook above, I would explode on the dash and check if the product ID is valid.

If you were to combine both fields together you could then use GF’s built in “No Duplicates” option in the field settings to make sure there are no duplicates. This would cut down on you needing to delete from your DB table and then re-adding it if ever that entry is deleted.

If you absolutely want to keep the two fields separate you could look into a plugin like Copy Cat to see if it would allow you to copy the values of product ID and product serial number into a third hidden field and that field could have the “No Duplicate” option activated.

Since you refered to products, I must say here that there are no products anywhere.
I’ve created a table in my database that has 4 columns. id, product_number, serial_number( this column contains all the 79 different serial numbers I need to validate) and in_use which has value 0 and 1. 0 if the serial number is not used and 1 if it is used.

The plan is that I need to validate only the form field named Serial Numbers. When I submit the form before the actual submit it must make a check in the above table I mentioned if the Serial Number the user has input exists in the table. If yes then the in_use column for the specific serial number should turn to 1.

Else if a serial number is already submited through the form, that means the in_use = 1 after the compare that will be done inside the database and then the form should not submit and display a notification of used code.

Well you asked if this was possible in GF and the answer is yes. You can use the hook mentioned above to validate whichever field you want to validate. Combine that with the “No Duplicate” option and you don’t need to worry about the in_use column.

If you insist on using that column then you’ll need to hook into gform_after_submission to toggle your value from 0 to 1 and then gform_delete_entry to toggle the value from 0 to 1 when it’s deleted.

This should be possible using Populate Anything. What you could do is populate a hidden field from your database and filter the results based on the user input. You could then set up conditional logic on the submit button that prevents submission if there’s no match. You could then set up an HTML field to display a message in place of the submit button when there isn’t a match, explaining why the submit button has disappeared. Rough example:

CleanShot 2023-10-31 at 14.33.55

As far as preventing the same number from being used multiple times, you could activate “No Duplicates” on the Product ID and Product Serial Number fields.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.