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.

RGFormsModel::get_leads and some weird behavior..

  1. Hey all,

    I've been using the RGFormsModel::get_leads() method to grab entries to a form, let's say form id #5, for use in some other code. I only want to grab entries whose first name field equals "Tom", for example. The first name field is field id #10.

    So, from what I've found, you'd call:
    RGFromsModel::get_leads(5, 10, 'DESC', 'Tom");
    Please correct me if I'm wrong here.

    However, what I find happening is this call will return results for "Tom" from *any field* in the entry. So if some named Paul entered "Tomato" as their favorite food, their entry is returned as well. It's like that second argument in the function call is completely ignored.

    Anyone else seen this happen? Seems to be a pretty significant bug if I'm understanding this function correctly. (And that's a big "if")

    Posted 8 years ago on Thursday March 8, 2012 | Permalink
  2. Hi, innovatagroup,

    The get_leads function does not allow you to pull leads by searching a specific field. The second parameter specifies by which field to sort the results. So, as you saw, if "Tom" is in any of the fields, that lead will be returned. We do not currently have a function that will allow you to select results by searching a single field, you would need to write your own database query. We can point you in the right direction if you need help with the query.

    Posted 8 years ago on Friday March 16, 2012 | Permalink
  3. Dana,
    Thank you for the reply -- I didn't realize that second parameter was the sort field. I was just piecing together the logic from looking at the core source.

    If you have some resource for creating a custom query, that'd be immensely helpful. I'm sure it would involve all sorts of "fun" joins, and someone with more knowledge of the software would probably have a better go at it. :)

    Posted 8 years ago on Friday March 16, 2012 | Permalink
  4. Hi, innovatagroup,

    I'll see what we can do.

    Posted 8 years ago on Monday March 19, 2012 | Permalink
  5. Hi, innovatagroup,

    Below is a sample query for you. Your table names may be different depending on your WordPress database prefix, but they should have "rg_lead" and rg_lead_detail" in the name. In the query below I am using form_id=53, change this to your form. I am selecting entries where the first name field has "dana" in it. My first name field is field id 1.3, but because the database field is a float, we use the BETWEEN clause and make the values a float, otherwise you won't get any data back. You would change this to your field id and still subtract and add to the field number.

    SELECT * FROM wp_rg_lead
    JOIN wp_rg_lead_detail ON = wp_rg_lead_detail.lead_id
    WHERE wp_rg_lead.form_id=53
    AND field_number BETWEEN (1.3 - 0.001) AND (1.3 + 0.001)
    AND value LIKE '%dana%'

    Let me know if you have questions.

    Posted 8 years ago on Monday March 26, 2012 | Permalink

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