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.

Best way to get entry id

  1. I'm using:

    global $wpdb;
    $result = $wpdb->get_results("SHOW TABLE STATUS LIKE 'wp_rg_lead';");
    $entryId = $result[0]->Auto_increment;

    Is there a better way to get the entry ID before its generated?

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  2. I don't know a good way to get the auto generated IDs before the record is created. The safe way to do this is to first create the record and then use $wpdb->insert_id to read the ID that was created.
    If you describe a little more what exactly you are trying to do, I may be able to help you with some alternatives.

    Posted 12 years ago on Thursday May 10, 2012 | Permalink
  3. I need to attach a reference number (entry ID) to a UPS label which is generated on gform_pre_submission_filter (before entry ID is generated) so that I can save the tracking number to a hidden field.

    The method in my initial post works, I just wanted to see if there was an official GF API call that did the same thing.

    Posted 12 years ago on Thursday May 10, 2012 | Permalink
  4. I see what you are trying to do, but I think this method is not 100% reliable. If two entries get submitted around the same time, you might end up using the wrong entry id. The chances of that happening are probably not very high, but it could happen. If you decide to do it this way, I would change the query to

    SHOW TABLE STATUS WHERE name='wp_rg_lead'

    If you don't want to take that chance, use the gform_after_submission hook instead, where you have access to the entry id, then manually change the value of your hidden field using a sql statement:

    $wpdb->query("UPDATE wp_rg_lead_detail SET value='TRACKING_NUMBER' WHERE lead_id=ENTRY_ID AND field_number=HIDDEN_FIELD_ID")
    Posted 12 years ago on Thursday May 10, 2012 | Permalink
  5. italianbird
    Member

    I need to reference the entry id in a newly created form field when a new entry is created. Perhaps pre-lead the entry id with the letters "CT". How can I make this happen? I'm not a programmer, but I follow instructions quite well.

    Posted 12 years ago on Sunday July 22, 2012 | Permalink
  6. @italianbird, can you explain your scenario in a little more detail so we can help you with detailed instructions? Thank you.

    Posted 12 years ago on Monday July 23, 2012 | Permalink
  7. italianbird
    Member

    I've created an additional form field called 'Internal Pro Nbr'. I'd like that field to be populated by the entry number that is already assigned to each new form submission or record. These numbers start with 1 thru infinity and indicated on each new record.

    What we'd additionally like to do is throw in pre-leading characters such as CT00(entry id#).

    Posted 12 years ago on Monday July 23, 2012 | Permalink