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.

Post as checkbox

  1. I need a way to make a checkbox field out of a post and meta data. Basically pulling all posts from a category, showing title, excerpt, featured image and an extra field. Tell me it can be done:)

    Posted 14 years ago on Tuesday November 9, 2010 | Permalink
  2. Would the resulting checkbox be part of the Gravity Form?

    Posted 14 years ago on Tuesday November 9, 2010 | Permalink
  3. Yes.. So in specific... post in category is a vendor name of the wholesale distributor. I want to show the list of vendors (with hopefully a bit of html around it) so that the user can check which vendors they want to get catalogs from...

    Posted 14 years ago on Tuesday November 9, 2010 | Permalink
  4. Here is a rough bit of code from a side project I did that will help you started: http://pastie.org/1285749

    add_action("gform_pre_render_12", "filter_lead_categories");

    Update the 12 to your form id.

    $posts = new WP_Query(array('category__and' => $catnames, 'posts_per_page' => 20));

    Customize the query to get the posts you want to display as checkboxes.

    $i = 0;
        foreach($posts->posts as $post) {
            $companies[$i]['text'] = '<a href="' . get_permalink($post->ID) . '" target="_blank">' . $post->post_title . '</a>';
            $companies[$i]['value'] = $post->ID;
            $i++;
        }

    This bit of code loops through the posts you queried and creates an array of choices that we will use to replace the existing choices for the field these checkboxes should appear in. By default, Gravity Forms will strip out HTML from the "text" property, but by adding an additional filter (gform_field_choices), we can allow HTML.

    $form['fields'][1]['choices'] = $companies;

    Update the 1 to the index of the field you would like to replace the choices with. You can view the page source to get this id.

    add_filter("gform_field_choices", "decode_specialchars", 10, 2);
    function decode_specialchars($choices, $field){
        $choices = htmlspecialchars_decode($choices);
        return $choices;
    }

    As mentioned above, the last part of this is making sure the HTML you add for the "text" property of each checkbox won't be stripped out by Gravity Forms:

    And that's pretty much it. This is a rough base, but hopefully it will give you an idea of all the pieces involved. :)

    Posted 14 years ago on Tuesday November 9, 2010 | Permalink
  5. Oh now that's amazing service. Exactly what I needed. I'm not finding much in the area of documentation surrounding this and probably could have saved you some time if the docs included some of this more advanced hook handling. But you saved me some time by giving me the answer outright so I can't complain!

    Posted 14 years ago on Tuesday November 9, 2010 | Permalink
  6. Working like a charm!!! Thanks man. I've just got to doctor up the html now and I'll be done:)

    http://www.creativeendeavorsinc.com/request-catalogs/

    Posted 14 years ago on Wednesday November 10, 2010 | Permalink
  7. One more question... See below:
    http://screencast.com/t/sbL493uJw

    The page is showing the dynamic posts from categories (with thumb and text:) but the email forwarding shows the prefiltered choices. Is it possible to filter the choices for email directing as well?

    Posted 14 years ago on Thursday November 11, 2010 | Permalink
  8. Unfortunately, this is not possible in the admin. The actual functionality of routing the emails based on the custom options is possible, but would require some more customization. Email me at david@rocketgenius.com and I can send you some code where I've done this for a side project.

    Posted 14 years ago on Friday November 12, 2010 | Permalink