PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Querying External Dataset to Validate Number Input

  1. I'm done some searching around the form and I'm just throwing this out there to see if anybody has any good ideas before I start doing anything with this. Here is the scenario:

    1. I have a form where users have to enter their ID number.
    2. I have a dataset that matches those ID numbers with their address.
    3. I need to validate that the ID they enter is in fact an actual ID and not made up.
    4. I also need to display their address on the screen below the ID field so they can make sure they input their ID correctly.

    My dataset that I need to validate against is quite large (1,818 IDs). They are a 7 digit number that all start with 0 and range from 0071264 to 0584684 and are obviously not consecutive numbers (that really doesn't matter too much I suppose). I can put this dataset wherever I need to, in the WP database, csv or text file on the server, etc...

    The ID number is the first thing they enter on the form and I need it to validate after they enter in their ID (not upon form submission).

    I also have the form setup to redirect back to itself with half of the form being filled in automatically via query strings from the initial submission. The reason for this is users will be submitting the form anywhere from 1-10 times to register each person in their group. I realize that will require the form to revalidate the ID number when the form loads again after redirection and the fields are filled in via query strings.

    So if you have any insight or if you've seen anybody do anything similar to this and wouldn't mind giving me a push start that would be awesome. Any other suggestions would be welcomed.

    Thanks,
    GB

    Posted 12 years ago on Thursday July 26, 2012 | Permalink
  2. Here is a good discussion regarding that:
    http://www.gravityhelp.com/forums/topic/database-look-up-validation

    I created a text file with 2000 numbers in it. Take a look at that and see if you get any ideas or need any help with that.

    Posted 12 years ago on Friday July 27, 2012 | Permalink
  3. Chris,

    This definitely helps out a ton! I've got the code you supplied working on my form(s). I'm trying to expand it a little bit by using a csv file instead of just a list of IDs in a single column. Here is an example of my dataset.

    I've got a script that I've stolen from php.net which splits this data from my text file into an array for each row and looks like this.

    The output of that script against my data looks like this.

    Is there any way you could help me marry your function with this csv to array script so it just searches the id's and the returns the three values within the matching ID's array as query strings?

    Thanks,
    GB

    Posted 12 years ago on Tuesday July 31, 2012 | Permalink
  4. Ok, I'm getting close I think in merging the two scripts. I've got a pastie with what I've got so far here: http://pastie.org/4379729

    I'm getting an error on line 69:

    "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in /home/ok/public_html/wp-content/themes/twentyten/functions.php on line 69"

    Am I missing something on how I'm passing those variables from Gravity Forms to this function?

    My data set still looks like this: http://pastie.org/4367213

    I haven't gotten there yet but I'm wondering if the query string will still work as well. What does the $lead array look like? Will I need to change that to look at my $csvdata array instead? I'll be wanting to pass all the values of the array for the matched ID. Meaning in my example data set I'll want to pass the ID, Name, and Town.

    Thanks,
    GB

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  5. Still wrestling with this... anybody have an insight to my error I'm getting?

    Posted 12 years ago on Tuesday August 7, 2012 | Permalink
  6. Are you still looking for help with this one? The topic was lost for a little while.

    The error on line 69 is because you are sending a constant, not a variable, to the function (the 'ID' part.) There's usually no reason to do that, as there is no reason to send something that does not change in the function call. That's why the error is thrown. You can do something like this:

    [php]
    $id = 'ID';
    function is_code_valid($csvdata, $id, $thiscode) {

    That would make the error go away, but I don't think it will make this work.

    On line 9 you call the function is_code_valid, with one parameter. However, on line 69, your function is using three parameters. There is probably a misunderstanding of some sort with that.

    Posted 12 years ago on Monday August 20, 2012 | Permalink
  7. Chris,

    Thanks for your reply. I've changed the ID as you described above. My 'ID' in this case won't change as that function will always be looking at just that ID of the first array value which is the first column in a text file. Anyway that did fix that issue.

    You were right about the other issue with only passing one parameter in the first function. I'm a little confused on that. I think the "$_POST['input_1']" should be "$thiscode" in my is_code_valid function. I added the first two paramaters to the function call on line 8 but now it just validates false every time. I'm sure I'm just not connecting the dots properly.

    Here is what things look like now: http://pastebin.com/UjxrLe4g

    Thanks,
    Grant

    Posted 12 years ago on Thursday August 23, 2012 | Permalink
  8. I'm still having issues with getting this working properly. I really need to get this working as it's for registration of an event that is in November.

    Thanks,
    Grant

    Posted 12 years ago on Tuesday September 4, 2012 | Permalink
  9. Please export your form, send your CSV, and your functions.php via email to chris@rocketgenius.com and I will have a crack at it.. Thanks.

    Posted 12 years ago on Tuesday September 4, 2012 | Permalink
  10. I emailed the actual code to Grant, but posted a generic version of the code here for anyone interested in this: http://pastebin.com/8LaYuDZs

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink