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.

Creating a directory w/Gravity Form and categories

  1. I'm creating a directory using Gravity forms. I've set up conditional fields which allow a company in the directory to choose 3 top level categories, and then each of those displays checkboxes for sub-categories.

    I'm not using WP native categories, but GF conditional fields.

    My question is, I would like to display a page where I list all top level categories, and if a user clicks on a category, "computers & internet" for example is a top level category with 6 sub-categories within it. Then if I click "computers & internet", I would load a page that lists the 6 sub-categories. Is there any way to easily generate this already available? The way my fields are stored in the database seems like iterating through it to located top level categories and sub-level categories could be a nightmare.

    thanks
    brian

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  2. There isn't a way to dynamically generate drop downs based on previous selections. Conditional Logic only works if the fields exist on the form. So there isn't an easy way to do this without adding a field for each conditional on the form.

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  3. Hi Carl,

    I'll try explaining this a different way, hopefully better than I did the first time. :)

    I have set up conditional drop downs that allows a user to select a parent category (not to be confused with WP's built in categories though) and then when a parent category is chosen it uses GF conditional logic to display a series of checkboxes with that parent category's child categories.

    I need to be able to display a page with a list of those parent categories on a page (I'm building a very traditional directory structure) and then have a page for each set of child categories.

    Because I set up the Parent categories and the child categories using GF Fields all of the data is stored in wp_rg_form_meta in the respective form's display_meta field. I just need a way to access it so that I can create a list of parent categories, and then, depending on which parent category is chosen, display a list of it's child categories.

    So I have created a drop down with a Field Label of Fitness and Wellness, where Fitness and Wellness is the Parent Category. I have bulk added 10 child categories (Counseling and Coaching, Exercise Equipment ,Health Clubs, Nutrition and Supplements, Pilates, Training and Conditioning, Weight Loss, Yoga and Meditation) to this drop down.

    There are 20 or so other parent and child category pairs that I have set up similarly and I want to display 1 page that only lists the parent categories and then have a page the corresponding child categories.

    Does that make any sense?

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  4. So what you want to do is query the entry data and get those categories and then display them using code code?

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  5. Yes, though in this case entry data would be based on what I have used for the Field Label (parent category) and it's options (child categories), not on the actual selections used per entry (or form submission).

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  6. I would like to query submission data either in or preferably out of the Word Press framework. Are there available function calls to get a submission object by it's id? Conversely, can you point me to the queries that Gravity uses to do the same for display in wp-admin?
    Just a whole lot easier when dealing with a bunch of em to just pass the ID to the confirmation script and query from there... Thanks a lot,

    Posted 13 years ago on Monday April 11, 2011 | Permalink
  7. Here is a sample query where we get all the details for each lead detail submitted from from ID 45 and field ID 3.

    http://pastie.org/1784415

    This sample code would output something like this:

    http://grab.by/9Rd2

    Posted 13 years ago on Monday April 11, 2011 | Permalink
  8. I've got two questions regarding the sql that David added to pastie.org. If I want to query an address (which in my form has a field_number=92.1 and a form_id=4, even though there area a number of records that have this field_number, the sql doesn't seem to work with any non-integer numbers.

    It will work if I use range, for instance > or < does work. So for example the sql below works and will return any records with a field_number between 92 and 93 (i.e. 92.5, 92.7, 92.8):

    SELECT * FROM wp_rg_lead_detail
    WHERE wp_rg_lead_detail.field_number>92 AND wp_rg_lead_detail.field_number < 93 AND wp_rg_lead_detail .form_id=4

    Why doesn't the query work if I try to get records where wp_rg_lead_detail.field_number=92.5?

    Posted 13 years ago on Wednesday April 13, 2011 | Permalink
  9. In order to build my parent categories list I need to access wp_rg_form_meta.display_meta field. I tried unserializing the data in this field however it gives me this error:

    Warning: unserialize() expects parameter 1 to be string

    How can I get the parent categories (in my case it is putting all of my parent category choices into wp_rg_lead_detail.field_number=5) out of that field if I'm unable to unserialize it?

    Posted 13 years ago on Wednesday April 13, 2011 | Permalink
  10. Hi Brian,

    To answer your first question, when querying field numbers which are floats it is probably easiest to cast the field number as a decimal. MySQL will return inconsistent results when searching for a float data type (more info on this here). Alternately, you can search by a range as you've posted above. Quick example of a query casting the field number as a decimal:

    [php]
    $removed = $wpdb->query("DELETE FROM $table WHERE lead_id = $entry_id AND form_id = $form_id AND CAST(field_number as DECIMAL(4,2)) = $field_id");

    For an easier way to retrieve the form meta, you can use this function:

    [php]
    $form = RGFormsModel::get_form_meta($form_id);

    Let me know if this does the trick for you if your requirements are more specific.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  11. Thanks David,

    When using the RGFormsModel::get_form_meta($form) is there a simple way to locate (or maybe display) the specific portion of the array I am interested in?

    For instance, I pasted the results of RGFormsModel::get_form_meta($form) into a text editor and slowly waded my way through it until I was able to identify the array data I was interested in ($form[fields][16][inputs][1][label]). But I'm guessing there is a simpler way? right?

    thanks
    brian

    Posted 13 years ago on Thursday April 21, 2011 | Permalink
  12. Try using this function to output the form meta:

    http://pastie.org/1820138

    You'll find that it is significantly more readable and gives you a better idea of hierarchy in the array.

    Use like so:

    [php]
    $form = RGFormsModel::get_form_meta($form);
    print_rr($form);
    Posted 13 years ago on Thursday April 21, 2011 | Permalink
  13. That's much better! Thanks David.

    Posted 13 years ago on Friday April 22, 2011 | Permalink
  14. Anonymous
    Unregistered

    Hi, I am pretty new to this, so I apologize in advance if I am making no sense.

    What i am trying to do is display 3 fields from our form on a page. I know the fom ID and the Field number(s). I just have no clue how to pull the data for those fields and display them.

    Thanks,
    Jen :)

    Posted 12 years ago on Thursday June 23, 2011 | Permalink
  15. Jen,
    Try the following. You will need add it to the template file you would like to display this information. Make sure to replace the Form ID and Field IDs to match yours.

    <?php
    //NOTE: replace 167 with your Form ID
    $entries = RGFormsModel::get_leads(167);
    echo "<table>
            <tr>
                <td>Field 1</td>
                <td>Field 2</td>
            </tr>";
    
    foreach($entries as $entry){
        //NOTE: replace 1 and 2 with your Field IDs
        echo "<tr>
                <td>{$entry["1"]}</td>
                <td>{$entry["2"]}</td>
              </tr>";
    }
    echo "</table>";
    ?>
    Posted 12 years ago on Friday June 24, 2011 | Permalink
  16. Anonymous
    Unregistered

    THANKS! It totally worked. I have a few other things I would like to try now.

    Only post active posts (do not show anything that has been deleted)
    Make 1 of the fields (post title) a link to the post
    How to combine First & Last name from form to show as 1 field.

    Any suggestions?

    Posted 12 years ago on Friday June 24, 2011 | Permalink
  17. Try the following. I am assuming your are using the default name field with First and Last names.

    //NOTE: replace 175 with your Form ID
    $entries = RGFormsModel::get_leads(175);
    echo "<table>
            <tr>
                <td>Name</td>
                <td>Post</td>
            </tr>";
    
    foreach($entries as $entry){
        $post = get_post($entry["post_id"]);
        if(!$post || $post->post_status == "trash")
            continue;
    
        $permalink = get_permalink($entry["post_id"]);
        //NOTE: replace 1 and 2 with your Field IDs
        echo "<tr>
                <td>{$entry["1.3"]} {$entry["1.6"]}</td>
                <td><a href='{$permalink}'>{$entry["2"]}</a></td>
              </tr>";
    }
    echo "</table>";
    Posted 12 years ago on Friday June 24, 2011 | Permalink

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