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.

Entry ID's

  1. Hi Guys,

    We've got two forms on the site, and I'm hoping to split the entry id's, or, set up a new, form specific, serializing number.

    So right now, if I submit to form A, then form B, then A again, the two entries for A are 1 and 3. Ideally, I'd love to set up a number system that goes A-1, A-2 etc.

    I kind of got a sense of how it might work in http://www.gravityhelp.com/forums/topic/modifying-the-entry-id -- but I'm not quite sure how to put it all together, nor am I quite sure where it goes (though, functions.php would be the default guess).

    Any help very much appreciated.

    -m

    Posted 12 years ago on Thursday August 23, 2012 | Permalink
  2. The code will definitely go into your theme's functions.php.

    Have you worked out any of the code yet?

    Posted 12 years ago on Friday August 24, 2012 | Permalink
  3. So: If I want to add and "A" for form 5, and store the new number in field "23" -- would it look like this?

    <?php
    add_action("gform_post_submission_5", "post_submission", 10, 2);
    
    $SubmissionID= "A" . $entry["id"];
    
    $entry['23'] = $SubmissionID;
    
    return $entry;
    
    ?>

    What does the 10,2 refer to?

    Thanks much!

    -m

    Posted 12 years ago on Friday August 24, 2012 | Permalink
  4. 10 is the priority, and 2 is the number of arguments the function accepts. Please see here for documentation of this WordPress function: http://codex.wordpress.org/Function_Reference/add_action

    Posted 12 years ago on Saturday August 25, 2012 | Permalink
  5. OK. The function as it stands doesn't seem to be doing anything (the field just comes through empty).

    Posted 12 years ago on Saturday August 25, 2012 | Permalink
  6. Tried wrapping it in a function -- still not filling the field. I'm sure I'm missing something stupid, but, what it is, I have no idea.

    Here's what I've got:

    function post_submission()
    {
    
    $SubmissionID= "A" . $entry["id"];
    
    $entry['22'] = $SubmissionID;
    
    return $entry;
    }
    add_action("gform_post_submission_1", "post_submission", 10, 2);
    Posted 12 years ago on Monday August 27, 2012 | Permalink
  7. Still looking for an answer...

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  8. I have your email Martin. Hang in there.

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  9. Hi Martin, this was more complex than expected. It is sort of a catch 22: you don't have the entry ID before the entry is written, so you can't use gform_pre_submission. And it's more complex to update an existing form field in gform_after_submission. Please give this code a try: http://pastebin.com/8jzCnSpK

    You should change '93' on line 4 to your form ID (was it 5? or 1?) and the number '4' on line 8 to your field ID (was it 22?) I was able to add a number like "A994" to my entry using this function. Let me know if you need additional help.

    The developers are considering adding a helper function to update existing entries so we don't have to resort to using wpdb.

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  10. Chris -- Worked perfectly! Many thanks!

    In future releases -- form specific id's would be rad.

    Thanks again!

    -martin

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  11. Quick question: I need to do this twice, but just dropping it in twice breaks everything -- is there a way to do two at once?

    Site breaking code here: http://pastie.org/4708732

    {Fatal error: Cannot redeclare add_submission_id()....}

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  12. David Peralty

    Give your second function a slightly different name. You can't re-declare functions like that. ;)

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  13. And... i'm an idiot. Thanks david.

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  14. So changing the function name stops everything from breaking -- but the second form won't take a new id? I'm positive I've got the form id and field id's right. Does that make any sense?

    http://pastie.org/4709058

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  15. David Peralty

    You aren't calling that "new function" in your second call:

    add_action('gform_after_submission_2', 'add_submission_id', 10, 2);

    should be add_submission_id2

    Posted 12 years ago on Wednesday September 12, 2012 | Permalink
  16. And, still and idiot. Thanks David. -m

    Posted 12 years ago on Friday September 14, 2012 | Permalink
  17. Are you all set now?

    Posted 12 years ago on Friday September 14, 2012 | Permalink

This topic has been resolved and has been closed to new replies.