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.

Getting a single entry as an object

  1. michaelbyrd123
    Member

    So I'm trying to figure out a mysql statement that will get a complete gravity form entry, given the lead id, as an object. Can anyone help? The reason I want to pull directly from the gravity form database is that I want the administrator changes through the entries tabs to be reflected, instead of creating my own database table when forms are submitted. So far i've got-

    SELECT wp_rg_lead_detail.value, wp_rg_lead_detail_long.value AS long_value
    FROM wp_rg_lead_detail
    LEFT JOIN wp_rg_lead_detail_long ON id=lead_detail_id
    WHERE lead_id=$id ORDER BY field_number;

    This works okay, and gets the complete lead, with it's field number sorted. I guess I sort of answered my own question ^^. I can then get the field value by using an if statement, getting the detail value if the long value is empty (actually youd probably want to include the field_number in your sql statement as well)

    Let me know if anyone has a better approach than this.

    Posted 14 years ago on Thursday December 9, 2010 | Permalink
  2. You got it! This is the way to do it.

    Posted 14 years ago on Friday December 10, 2010 | Permalink
  3. michaelbyrd123
    Member

    Okay, so this has been working good but now I need to take it a step further and am getting a bit stumped. I now want to convert all of the field_numbers into their appropriate title. For example in a simple form they might be 1, 2.1, 2.2, 2.3, 2.4, 3.

    How would I go about converting these to their respective titles? The info I need seems to be stored in an enormous string in wp_rg_form_meta. Is there a built in function I can use to get the headings given the string?

    Posted 14 years ago on Monday December 13, 2010 | Permalink
  4. Yes, the field label is stored as a serialized string, so you won't be able to get them all at once. You will need to get them one by one, using the following PHP code:

    //Replace 10 with your form ID
    $form_meta = RGFormsModel::get_form_meta(10);
    
     $field1 = RGFormsModel::get_field($form_meta, 1);
     $label = $field1["label"];
    
    $field2 = RGFormsModel::get_field($form_meta, 2);
     $label2 = $field2["label"];
    Posted 14 years ago on Monday December 13, 2010 | Permalink
  5. michaelbyrd123
    Member

    Woohoo worked like a charm. Thanks for the quick response. So glad I bought dev license so far ;]

    Posted 14 years ago on Monday December 13, 2010 | Permalink

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