Require an Existing Value for Submission with Gravity Forms
Ensure that a value entered in Form B has been previously submitted (or generated) on Form A. This is useful if you’re generating a reference number of some sort on Form A and would like the user to enter it on Form B.
December 11, 2023: Fixed compatibility issue with Gravity Forms 2.8.
June 22, 2022: Improved support for validating field map via AJAX.
Let’s say a reference number is generated on Form A (using something like GP Unique ID) for the user’s order (represented by a Gravity Form entry). The reference number is emailed to the user.
On Form B, the user is able to contact you about their order by entering the reference number. If they fail to enter a valid reference number, a validation error is returned and they are unable to submit the form.
Looking for an simple way to generate a reference number for your Gravity Form submissions? GP Unique ID for Gravity Forms can help.
Check out this step-by-step tutorial on how to use GP Unique ID to generate a reference number for your Gravity Form submissions and use this snippet to validate those reference numbers on subsequent submissions.
How to Generate and Validate a Reference Number for Gravity Forms with GP Unique ID
Getting Started
- Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Make sure you have Gravity Forms installed and activated.
- Install the snippet
- Copy and paste the entire snippet into your theme’s functions.php file.
Configure the snippet
Once you have installed the snippet, look at the bottom of the snippet for this block of code:
new GW_Value_Exists_Validation( array( 'target_form_id' => 123, 'target_field_id' => 1, 'source_form_id' => 124, 'source_field_id' => 1, 'validation_message' => 'Hey! This isn\'t a valid reference number.' ) );
- The target form ID and field ID represent the form and field that should be validated and show the validation error when validation fails.
- The source form ID and field ID represent the form and field that store the existing value that the value submitted in the target form and field should be checked against.
- The validation message can be updated to any message you would like to indicate that the entered value did not match any existing values in the source form and field.
Parameters
target_form_id (integer) (required)
This is the Form ID for the field that you will checking if a value already exists (Form B in the example above). There is no default value.
target_field_id (integer) (required)
This is the Field ID for the field that you will checking if a value already exists (Form B in the example above). There is no default value.
source_form_id (integer) (required)
This is the Form ID for the field that generated the reference number (Form A in the example above). There is no default value.
source_field_id (integer) (required)
This is the Field ID for the field that generated the reference number (Form A in the example above). There is no default value.
validation_message (string) (optional)
This is the error message that will be displayed if the value being tested does not already exist. Defaults to
"Hey! This isn't a valid reference number."
field_map (array) (optional)
An array of target and source field IDs; allows for creating multiple requirements that must match the same entry. Format should be:
array( // SOURCE_FIELD_ID1 => TARGET_FIELD_ID1, 2 => 3, 5 => 11 );
disable_ajax_validation (bool) (optional)
Optionally disable AJAX validation. AJAX validation is enabled by default and will add a checkmark or an x-mark depending on whether the value exists.
validate_blank_values (bool) (optional)
Set to
false
if you wish to disable validating blank target field values.
Validate phone numbers on your forms in real time with Gravity Forms Advanced Phone Field! This perk also detects country codes automatically, formats numbers accordingly, and provides animated drop down selects (complete with flags 🇺🇸).
Any questions?
This snippet is more of a building block rather than a final solution. Let us know how you’re using it and any questions you have about building on top of it to accomplish a more involved solution.
For an example of how this can be combined with other plugins to create a more robust solution, check out the How to Generate and Validate a Reference Number for Gravity Forms with GP Unique ID tutorial.
We hope you find this snippet useful! If you do, show us some love by sharing this article on the social media platform of your choice. Let’s keep the Gravity Wiz pumping out awesome snippets.
I was so excited to find something that would give me and my team an invite-only solution for an upcoming event. We are allowing additional guests to attend this paid event. For this, we are using Gravity Forms Stripe Add On and GP Auto List Field so that guests can add the names of the additional people they are purchasing tickets for. The Unique ID worked perfectly, but then I noticed that the Auto List Field no longer worked when I increased the tickets on the form. Additionally, the Stripe credit card form stopped working. I was hoping to get this up and running, as this event is on May 31. I hope I can get some feedback here! https://lcosfounders.com/rsvp I should also add that when I turned off the snippet in functions.php, the problem went away.
Hi Jessica,
I see that you’ve also sent us a ticket about this, I’m just letting you know that we’ve replied there.
Best,
Is there a limit on the number of times the referral code can be used? If that is not included in this code, would I need to use a Limit Entries perk or would that work here?
Hi Chris,
Limiting the number of times a code can be used isn’t supported with the code snippet. You can however do this with our GP Limit Submission Perk. You can use the field value rule group to limit the number of times a code can be used. The check for this will be done when the form is submitted.
Best,
Hello!
Thanks for the snippet. Can I customize it so that the entry is checked against a column in a custom database?
The solutions here in the comments from 2015 are no longer available.
Thanks a lot!
Dang. Looks like that snippet is lost to time. I don’t have a ready solution for this but I bet ChatGPT could whip something up for you. If you’re a Pro customer and prefer to have us write a snippet for you, drop us a line via support.
Thank you for such a great snippit! I’ve included the code in a custom plugin I am using for other functions as well. However, I am getting a console error: ncaught ReferenceError: GWValueExistsValidation is not defined
Can you help me sort that out?
Thanks!
Hi Alison,
That error indicates that the full snippet code wasn’t included in your plugin. Make sure to include the entire snippet code.
I have a nested form using product/option field combos. I’m trying to make sure the end-user is completing the option field if they select a choice on the product field. I’ve tried conditionally showing HTML fields if option field x is empty. While that does work, the HTML fields don’t disappear when the issue is corrected.
Is there any other way to make the option field conditionally required if a specific selection is made?
Hi Heather,
I have just sent you an email to follow up about this, as I’d like to get some more information about your specific set up.
Best,
Thank you for this. Assuming an incorrect value is entered and the form is submitted – is there a way to have Gravity Forms identify that as a Submission? I would like to give users 3 tries to enter a correct value, and then prevent them from submitting more entries if they do not enter correctly. I know I can limit submissions in the form settings, but it does not seem like this code actually submits the form, just shows the error.
Hi Manuel,
The functionality of the code doesn’t allow the user to submit the form if the value entered is incorrect, so it won’t work for your use case. To get it working the way you want, may require some customization to the snippet. If you have an active Pro license, you can contact us via the support form, so we look into this further.
Best,
I have successfully installed the snippet and everything works great targeting one ‘source_field_id’ to one ‘target_field_id’. My issues arise when attempting to use the ‘field_map’, and I am likely not using it correctly (in all honesty).
In my original attempt at mapping 1 to 1, this works great:
‘target_form_id’ => 11, ‘target_field_id’ => 2, ‘source_form_id’ => 4, ‘source_field_id’ => 98,
Where mapping field 98 (email address) from form 4 to field 2 (email address) on form 11, again no problem at all.
What I am attempting to do is take multiple source fields from form form 4. This was a event registration form, so depending on the number of attendees registered I have multiple email address fields. I want the validation to occur across each field, then they can proceed to a page to download documents from the event.
Here is what I tried:
new GW_Value_Exists_Validation( array( ‘target_form_id’ => 11, //’target_field_id’ => 2, ‘source_form_id’ => 4, //’source_field_id’ => 98, ‘field_map’ => array( // SOURCE_FIELD_ID1 => TARGET_FIELD_ID1, 98 => 2, 37 => 2, 41 => 2, 45 => 2, 52 => 2, 66 => 2 ), ‘validation_message’ => ‘Hey there! Does not look like you were an attendee.’, ) );
What happens is in the above, no entered values work. If I comment out all but 1 line in the array, that fields values will validate.
I am missing something, likely very simple, but for the life of me I cannot figure it out.
Jeff, the snippet setup seems correct. If it is not working for you something else must be going on. You can try by removing from the map attribute 98 and 2 as the field ids since both are already set in the target_field_id and source_field_id attributes.
If you’re having any difficulties setting this and if you have an active Gravity Perks license, contact us via our support form, so we can look at your setup and assist you further.
Thank you Dario, I have tried your suggestion and am still in the same position. With the field_map function in place it fails to validate against ANY of the source_field_id’s. As soon as I comment all but one of the out (I have tried each one) I can validate an email address for the respective source_field.
I do consistently see the following in the browser console, though I see it whether this is working or not:
Uncaught ReferenceError: GWValueExistsValidation is not defined
Unfortunately I am not currently a Gravity Wiz customer – wonderful product addons for sure. I just have not had a need yet to purchase. I feel though that that is coming soon.
Just in case, since it got ugly when I pasted it before
https://codeshare.io/0gKdNg
Hi Jeff,
I’ve just sent you an email to follow up about this.
Best,
Hello, I have used it and it work very well for me, but I faced an issue, assuming the source field ID is ‘200’ and the target field ID is ‘222’ the code will be able to validate any values entered in the field 200 without checking the entry ID. because I am using this code for validating a secret code sent to users but I want to make sure that it wont be validated if the user didn’t use the exact value he received.
Hi Omar,
If the codes are unique per entry, this snippet will validate each unique value for each entry. If you’re using the same code across multiple entries, this snippet will not differentiate between the different entries. If you need a way to generate unique codes per entry, check out GP Unique ID.
Hello Scott, The code is unique for each entry as I am using GP Unique ID and it is generating a different value each time, but the target field accept any values generated by GP Unique ID for source field.
Hey Omar, not sure I’m tracking but since you’re a Gravity Perks customer, drop us a line via support so we can dig into the specifics of your configuration.
This is a great post, and really helped me out with a client task.
A heads up I did find one bug, though, having to do with the field_map array:
The article (and a comment below) describe the syntax of the field_map array as TARGET_FIELD_ID1 => SOURCE_FIELD_ID1, but the correct usage is SOURCE_FIELD_ID1 => TARGET_FIELD_ID1.
Otherwise, it worked great. Huge thanks to author Mr. Smith and commenter Akter.
jason
Hi Jason,
Thanks for pointing this out. We’ll work on getting the article updated.
Best,
Hello, I’m trying to understand if GP Unique ID is the right solution (and how) for my needs.
Let’s say that I have a form which collects: – Name – Email – an optional Referral Code Each submitted entry generates an Unique ID (which can be distributed and then used by others as optional Referral Code).
Scenario: – UserA submits an entry to the form and gets xxxxxx as Referral Code. – UserA gives xxxxxx to UserB – UserB submits an entry to the form and use xxxxxx as code. – I need that UserA gets an email that confirms that UserB used his code.
Is that possible? How? Thank you in advance.
Hi Matteo,
GP Unique ID would work for the referral code. However, you would also need our GP Populate Anything Perk to populate a Hidden Email Address field on the second form, with User A’s email address matching the referral code entered by User B. You can then set up a Notification to send an Email to User A using the populated Email Address. You will have to set up conditional logic on this notification to send only if the hidden Email Address field is not blank.
I hope this helps.
Best,
When I add this to my function.php the site won’t load
Neverminded, I figured it out. Accidentally added a comma
Hi Daniel,
Ok no worries thanks for updating us. You’ve got to watch those sneaky commas :) .
Cheers,
Brad
Validating a single field is working as expected, but I need some basic help in validating two fields. I’m not sure how to set up the array. The single field validation configuration: http://snippi.com/s/y7c5deo
Hi Brian,
You will need to add two instances of the configuration to validate two fields. In the snippet you’ve sent, there’s only one. If you have an active Gravity Perks license, can you get in touch with us via our support form.
Best,
Hi David,
I would love this exact snippet doing the opposite. If the value entered already exists within all the forms entries, users should get an error message and can’t submit the form until a unique value is entered. Is there a version to do the exact reverse by changing the true and false states? I have tried the limit submissions but it doesn’t pick up previous entry fields?
Hi Ozz,
We’ve already followed up on this via email, but I wanted to post this in the comment thread so other customers could see it.
Limit Submissions Perk should work when using a Form Field value as a limit.
Best,
I have a theoretical question. I’m using Gravity Forms for support tickets, but only certain websites are eligible for support. I want to validate their website. Could I create a user registration form (Form A) where they put in their website address and then use that form as a source of validation that their website is covered on Form B? Also, lets say their support coverage ends on that website, would I need to delete the entry in Form A, or could I use the field_map parameter to look at a field in Form A that shows whether that website’s support is active?
Hi Brandon,
Your solution looks like a good one and it should work perfectly for what you want to achieve. Form A, which is the user registration form will contain the entries with website addresses that Form B will use to check if a User’s website is eligible for support. Currently, you’ll have to delete an entry if a user’s support coverage ends. However, if you’ll want to keep those entries when the support coverage ends, a workaround will be to manually append a text to the website URL on the Entry page, so that when a user enters it in Form B, there wouldn’t be a match.
Best,
Hi,
How would I go about using the snippet for multiple forms. Example: I want to validate field id 1 in form 1 against field id 2 in form 2, but then I also want to validate field id 1 in from 3 with field id 2 in form 4. So basically more than 1 source id and target id. I tried to copy the code twice in functions.php and renaming the class and some of the functions, but looks like it calls the init of the first.
Thanks, Marcel
Hey Marcel, check out our article here https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/ on how to add multiple instances to your same function. Let us know if you have any other questions.
Hi,
this does not seem to work across forms,but only when source and target form ids are the same…. is there a bug?
Thanks, Marcel
Hello Marcel, make sure you’ve installed it correctly to start: https://gravitywiz.com/documentation/snippet-troubleshooting/ The demo is still working so this is likely a configuration issue. If you are still having the issue let us know what version of WordPress and Gravity Forms you are using.
How would I add a date condition to the validation? So not only does the code but it validates the date as well. For example it validates the code and also the date_created against the current date. Where the current date is not more than 3 days from the date_created.
Anyone have any ideas?
Hi Churmi,
This may be possible with some changes to the snippet, but unfortunately, we are unable to assist with snippet customizations at the moment.
Best,
while enabling this script, the “Skip Pages on Multi-Page Forms” script is not functioning
Hello Jasim, could you please let us know which snippet you are refering to? Thanks!
While adding “Multi Page Auto Advance for Gravity Forms” https://gravitywiz.com/require-existing-value-submission-gravity-forms/ snippet to the theme config.php, the “Skip Pages on Multi-Page Form” https://gravitywiz.com/pro-tip-skip-pages-on-multi-page-forms/ snippet stop working
sorry function.php – not config.php
Hello Jasim, I just tested this out on my test server and cannot recreate this issue. Both snippets are working perfectly fine with one another. Are you adding ?form_page=2 at the end of your URL? What seems to be the issue? Could you run a theme/conflict test?
Will this work to cross validate between forms? Example: Check if name and dob exists from form a to form b.
Thanks
The snippet is not working for me and I am unable to determine why. HELP
Hi Kimberly, make sure you’ve installed it correctly to start: https://gravitywiz.com/documentation/snippet-troubleshooting/ The demo is still working so this is likely a configuration issue.
Looking for help to use this snippet Hey can you we validate to target ids in the form A with one source id in Form B ? if yes what changes need to be done in the code above?
Not sure I understand, Hammal?
@David. I mean I want to validate the code in two different places in form A and both the code as the same source Form B how can I do that.
I can modify for the user only have access to the form if the payment of woocommerce is marked “Completed”?
Hm, I don’t have a ready solution for this one.
Hi, Thanks for your previous reply. Is it possible to have multiple instances of this snippet e.g. for two separate forms? Can you explain how? Thanks!
1) Same question as Adesola 2) Can I validate against the “Entry ID” field? how do I get the ID of that field? Thanks!
Looks like you can just set “id” as your “source_field_id” parameter. Something like this worked for me: http://snippi.com/s/46u74sr
Hello david, how do I bulk generate unique membership Ids for users that had already submitted entries before the unique ID field was added to the form?
Hi David, I found your script and I wonder if it can be a base for a solution from my task. I tried to customize the script, but it does not work. Is there a chance to help me?
May task: I have 3 relevant fields: 1: username 2: projectnumber 3: shared username
If a user creates an entry to be searched if the same number already exists in another entry. If the number already exists the username of the first user should be entered in field 3. The reason is the following: it is allowed to use identical numbers multiple times. but the users should be shown, which user has already used these identical numbers.
Kind Regards Michael
Hi Michael, unfortunately, we just don’t have the throughput to help out with snippet customizations. :/
Hi, Thank you for your great effort. I tried to use it and it did work however when i try to use the field_map, it doesn’t stick to the pointed source_field_id only but it also accepts any entries from other fields ids if the entered value matches. My example below: the field id 12 – form 18 should only validated through field id 5 – form id 17 and the field id 6 – form 18 should only validated through field id 3 – form id 17 but what happens is that if the entered value in field 12 matches an entry value at field id 3 it marks it as valid and continue and same for field id 6 and source field id 5.
Please help.
Thanks in advance
Trying removing these lines form the configuration:
‘target_field_id’ => ” ‘source_field_id’ => ”
Hi, Thanks for the wonderful snippet!
Question: When validating an ID generated from form A in form B, is it possible to parse another field value from the form A submission with the matching ID?
For instance: Form A collects an email address, generates an ID and sends it there. When validating ID with your snippet in form B, I’d like to parse the entry with the matching ID for the email address for the purpose of emailing a confirmation.
I think I can tease out the matching gravity forms entry with this part of the code, but need a little guidance. Thank you!
Hi Tim, this would require some customization of the snippet. Not terribly difficult if you have some PHP experience but more than I can provide instruction on here.
I do have some PHP experience and a lot of JS. Any help greatly appreciated — thank you!
Hello,
I am not getting an validation error when the unique id is submitted to the second form and also the form getting submitted without filling other required fields.
Thanks in advance
Hi Nilesh, I’ve confirmed this snippet is working (via the demo). First, confirm you’ve installed and configured the snippet correctly (extra tips here). Next, try disabling all other themes and plugins to see if there is a theme or plugin conflict.
Nilesh, have you fixed your problem? I have the same issue, i´m not getting validation, have wordpress 4.4.2 and Flat Bootstrap theme Versión: 1.9 by XtremelySocial, perks installed an GP Unique ID activated. The snippet is configured in functions.php file. Please Help
Hi Armand, if you’re running GP Unique ID, drop us a line via support. We’ll be happy to help you figure this out.
Hi Dave, thanks for such an awesome solution.
Can you give an example code in reference to overwriting the “does_value_exist” method to validate/require a field from a database value? Say the meta-key is ‘card_id’ located in the wp_postmeta table.
Thanks, Ike
Hi Ike, something like this: http://snippi.com/s/uudsqa8
Hi David Smith, Nice work. Everything is fantastic. But, It will be better if you describe something about the ‘field_map’ parameter. I guess, you have added this for supporting multiple fields validation at a time. If I am not wrong, this is kinda like this: Values of Fields 1 & 2 of Form B will be validated by Fields 1 & 2 of Form A. Isn’t it? Can you please write some example on how to use this parameter? Should I keep empty on individual target_field_id & source_field_id if I declare them on ‘field_map’?
Thanks in Advance!
Got the features of ‘field_map’ parameter: Use it like-
Configuration
new GW_Value_Exists_Validation( array( ‘target_form_id’ => 22, ‘target_field_id’ => ”, ‘source_form_id’ => 21, ‘source_field_id’ => ”, ‘validation_message’ => array(1=>’Your Username may not satisfy the current policy requirements. Please try carefully!’, 2=>’Your Password may not satisfy the current policy requirements. Please try carefully!’), ‘field_map’ => array(1=>1, 2=>2) //target_field_id => source_field_id, to => from ) );
Also change this to line 55, if you need different validation message based on field-
$field[‘validation_message’] = $this->_args[‘validation_message’][$field[‘id’]];
Cheers!
Glad you were able to get this figured out. I’ve updated the article with a little documentation for the “field_map” parameter.
Hi,
I want this exact snippet doing the opposite. If the value entered already exists within all entries, user should get an error message and can’t submit the form until a unique value is entered. Thanks.
Hi Jose, do you mean you need Gravity Forms “No Duplicates” feature but apply it to all fields of all forms?
Hi, i´m using this snipet and it works fine, im validating in form B with a value of form A. but now i have another requirement with the same case: The data validated is an id number in the form A, the field 2 in form A is the name of the user, i need to print that name (from the same entry that the validated number id) in the field after the validated field in form B.
Anyone knows how to help me with this??
Hi Victor, we do not currently have a solution for this. Let us know if you come up with one. :)
Hi Nick. Thanks for the follow up.
For my specific issue that you responded to – I ended up going in an entirely different direction… now I have a single GF input promo code box that uses conditional confirmations. the default action is an in-valid entry that displays an error message indicating an invalid entry, and then each conditional confirmation is triggered based on the correct promo code being submitted. using the Gravity PDF plugin, I set up a different PDF document for the output associated with each valid entry (because each is different). so, when the right code is entered, the site admin gets an email, the user gets a printable PDF certificate that explains what their discount / incentive is, and the client gets a new email in their CRM and a legitimate follow up opportunity.
So for this one, I think I’m OK for now. But…. I would like info on any custom work you may offer for extending Gravity Forms!
Thanks again for the follow up and let me know the best way to ask about some special needs I currently have.
:)
Hi. I love Perks and your great library of snippets!
A question I have relates to validating an existing code – not one generated by a previous form.
so I was wondering… can I use a form to create a specific unique ID (lets call this form A). then direct customers to my site to input a pre-set unique code (created using form A) on a new form (form B). Why do I need this? because have advertised a specific promo code of ABC123 in a magazine, and different code of DEF456 in another. I want to specify pre-determined promo codes for tracking purposes, while preventing random entries from successfully submitting the form.
make sense?
Hi Neil, it’s been a while, but if you’re still in need of this functionality, I’d love to work with you. Get in touch.
Hello, I have this feature working, however, I was hoping you could help me get to the next step.
After the user has put in the correct validation code, I need to redirect them back to the form submission for which the validation code was generated.
To clarify: User completes form A User receives confirmation with validation code User goes to form B User enters validation code User is taken back to view what was submitted on form A
Thank you in advance for any help. Nick Brown
Hi Nick, I don’t know of a solution for this right now. It might be possible to configure with Gravity Flow.
[…] Gravity Wiz posted a couple of new Gravity Forms tutorials this week: how to generate and validate a reference number from your form, and how to require this value to submit another form. […]
Hello David, I’m sorry to keep bothering you but I really have tried to adjust your snippet to use more source forms than just one but it even failed with only two. Please, let me know if you can help.
Juan Carlos
Hi Wiz,
Great product! Love your work. But I have this strange problem with the number field. When I use the random number generator and I get for example 0001, the number field removes all the beginning 000’s. Is there any way I can prevent the number field to remove the first 0, or is the only solution using a text field?
Thanks for your support!
Robert
Hello David, Thank you very much for the awesome snippet but I do require to look the “source_field_id” from several forms (15 in total). I did look at https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/
I tried this:
foreach( array( 17, 31, 46 ) as $form_id ) {
new GW_Value_Exists_Validation( array( ‘target_form_id’ => 56, ‘target_field_id’ => 1, ‘source_form_id’ =>$form_id, ‘source_field_id’ => 11, ‘validation_message’ => ‘Your e-mail does not exist in none of our forms.’ ) );
}
but did not work. Could you please show me the right direction?
Thank you in advance.
JC
When you say it does not work, could you clarify on what you are experiencing?
Hi David, Thank you for replying. When I say it does not work I mean that, the way I understand, is that when you provide all the source_form_id in the array it should look trough all forms into the source_field_id (which is the same for all 15 forms).
I put an email for that exists in one of the forms, but it does not find it. Therefore the email is not saved into the new target form.
How do you make sure that it is looping trough all the forms searching for the source_field_id in the array?
Thank you.
Hi!
Is there a way to validate 2 fields? Like a combo of a serial number and dropdown list?
So when I validate, the serial number must match the option from the dropdown from the entry?
Thank you very much!
Hi Jen, do you mean:
a. Validating a serial number on Form B against a drop down on Form A? b. Validating a serial number on Form A against a drop down on Form A?
The answer to (a) is yes, this is possible with this snippet currently. The answer to (b) is also yes, but would require additional custom code. Here’s a tutorial on implementing custom validation:
https://www.gravityhelp.com/documentation/article/using-the-gravity-forms-gform-validation-hook/
Hi Greg!
what i meant was, both serial number and dropdown options in Form B to be validated from Form A.
I have managed to use this to validate the serial number, but how to get the dropdown options?
The combination of number + option entered in Form A must match when you enter a value in Form B.
Hope I make sense. thank you so much :)
Hi David, i’d like to sell the refernce number. So what you suggest me? if i use, for exemple, woocommerce, i can pass the number sell on the form created with gravity form? There is a way to sell a code, like a password for a premum content?
Hi Giacomo, there are many questions that would need to be answered before I could offer any useful advice on this. I would suggest hiring a developer to assist with this.
Any way to check two variables in order to validate an entry? I would like to get the same result as in user/password validation (but not to create a new wordpress user for each one)
Example: Field User + Field Password Check if user is valid from a list (this script already does that). Check if the password is valid for that user.
Any idea?
I’m trying to do what Greg was inquiring about, but I’m not familiar enough with PHP to integrate the CSV reference. What am I missing?
Hi Jessica, you can pick up a copy of Gravity Forms Entry Importer to handle the CSV to Entry conversion.
Thanks Greg,
I picked up the Gravity Forms Entry Importer, and have my CSV uploaded to the form field. Unfortunately, I’m not having luck getting it all to work. I am testing this with a code that I know isn’t on the list, and it’s giving me the validation error message (which is good, yay!), but when I test it with a code that I know is on the list, I get the same validation error.
Here’s what my code looks like:
Configuration
new GW_Value_Exists_Validation( array( ‘target_form_id’ => 1, ‘target_field_id’ => 3, ‘source_form_id’ => ‘/RSVPcodes.csv’, ‘source_field_id’ => ‘RSVP Code’, ‘validation_message’ => ‘Hey! Don\’t be a villain! Provide a legit RSVP code to reserve your spot at the Smackdown.’ ) );
In this instance 1 refers to the form ID, 3 is the field ID, /RSVPcodes.csv is my database reference, and RSVP Code is the name of the column with my data. Do I need to edit the code elsewhere? Is this code incorrect? Any help would be greatly appreciated.
See it all in action here: http://www.bbgraphics.com/halloween/index.php/rsvp/
Can I use the code twice in the same functions.php file to perform two validations by only changing the parameter values?
Hi Martin, absolutely. Here’s more info: https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/
Hello and thanks for the awesomeness! This is seriously cool and alone is worth the license! :) Now please, go that extra mile to save my day! :D
I need a help: I’d like to use this system WITH A CONDITION. The logic would be:
IF form field X is VALUE, skip the validation; ELSEIF form field X is ANOTHER VALUE, validate.
The reason for this request is that the user is prompted with a yes/no question. If they say yes, I need to check if they have a code; if they say no, I don’t need to check anything and the field containing the code to validate doesn’t even appear.
But, unfortunately, if I don’t find a way to skip validation, the hidden field will ALWAYS output an error. (and, no, I can’t work around it by setting a default value, as I need “no-duplicates” option).
I have an understanding of PHP, but I’m no expert. I’d probably find a solution, given enough time, but I’d LOVE to avoid all the headache and get the correct answer asap. ;)
Regards Max
Hi Massimiliano, I’ve just updated the snippet so that if a field is hidden via conditional logic it will no longer be validated by this snippet. :)
I had no idea the solution could be so beautifully simple. :) Your solution was even better than my proposal, so kudos to you! ^_^
Now the concept is really complete, allowing for example to create custom registration forms in GF, where the user can choose the level and is requested a code accordingly.
Coupled with a decent membership plugin, this is a real jewel! Give a special membership level to buyers, another to cooperators, another to… I don’t know… your grandparents, each one protected by a different password, or set of validation codes.
I’ve struggled to achieve something similar for a long time, but it was too niche to find a tutorial, and not important enough to justify hiring a more experienced person.
As far as I know, there’s no other way in wordpress to do similar things which is at the same time:
You might want to consider evolving this into a Perk, maybe with a backend page to handle the configuration and adding some options (although I consider this version absolutely mature now – maybe validate against a custom db table, as Greg suggested).
There might not be MANY people out there, with a need for this. But those who are, will definitely love you.
Which actually leads me to ask: how can we set this up so that we can validate as follows?
FORM_X, FIELD_Y vs FORM_A, FIELD_B (like now) and also FORM_X, FIELD_Z vs FORM_A, FIELD_C ?
Some guess work to make my question more clear:
foreach( $result['form']['fields'] as &$field ) {
Would something like this (probably not exactly like this) work to make both validations possible? I’m assuming I’d add more source_form_ids and source_field_ids as needed.
Otherwise I could save different validation functions in separate custom plugins… no problem about that. Any caveat you wish to share for this solution?
Thanks in advance Massimiliano
Could this be used to validate/require a field from a database value? Looking for a way to have users enter a unique product serial number that we have already entered as either a custom table value or as a taxonomy value.
I have a similar need and I very humbly suggest you my planned workaround for this problem: bulk import form entries from a csv file.
Might not be the most elegant solution, but at least you’d keep the custom code and the hassle to a minimum.
Anyway, considering when you posted, I hope you found a solution already. ;)
Missed your comment, Greg. Sorry about that. Massimiliano’s suggestion is a viable, custom-codeless solution. If you’re comfortable dipping your toes in the code, you could just overwrite the “does_value_exist” method in the snippet to query your custom table instead of GF entries.