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.

Problems applying custom checkbox values to gform_post_data

  1. Hey there!

    So I've got a form which needs to dynamically create a group of checkboxes based on a custom taxonomy and then, when submitted, apply those values to the post that is getting submitted (a custom post type called "marblestag_band").

    So far, my code successfully retrieves the custom taxonomy values and applies them to the form (so I successfully end up with a group of checkboxes with correct labels and values for each term in the custom taxonomy). The form also successfully creates a new post of the custom post type in the WordPress back end. Unfortunately, however, it does not apply the checked values to the post, so it does not get categorized at all.

    Looking into this, as far as I can tell the only way to define specific terms for a custom taxonomy for a post is to do so using wp_insert_post and the 'tax_input' array. If I hard code the values into gform_post_data (for example, if I put in $post_data["tax_input"] = array('genre' => '3,4,5'), the correct custom terms get applied to the post. However, when I try to pull those values from the checkboxes themselves, the terms get lost.

    I then wanted to test what values WERE getting pulled: apparently it's the old default values for the original checkbox (BEFORE the custom taxonomy options were added to the checkbox field). So let's say my checkboxes are input 14 and the original values are the default "First Choice", "Second Choice", "Third Choice" but my custom taxonomy terms are "Rock", "Pop", and "Soul". Using my code, they display on the form page as "Rock", "Pop", and "Soul" (as they should) but gform_post_data retrieves their values as "First Choice", "Second Choice", "Third Choice" (which is incorrect).

    It appears that gform_post_data is getting its information BEFORE the form is getting updated by gform_pre_render.

    You can see the code I wrote for this here: http://www.pastie.org/1855574

    Bottom line is this: I would like to apply dynamic custom taxonomy terms defined by checkboxes to my posts from Gravity Forms. The way I'm doing it right now seems like it should work to me but doesn't. Anyone have any ideas what I'm doing wrong?

    Thanks in advance,
    --eric

    PS - What's doubly weird is that if I use a drop-down instead of checkboxes, it works. But I need checkbox functionality.

    Posted 12 years ago on Monday May 2, 2011 | Permalink
  2. You might be right about the order of events. I will take a look at it.
    But I made some changes to your code, and I think I have a version that will work for you.
    The one change you will need to make is replace the "3" with the actual category name in the following line:

    $genre_string = "3,"

    The tax_input parameter expects category names, not ids.

    http://pastie.org/1857344

    Good Luck!

    Posted 12 years ago on Monday May 2, 2011 | Permalink
  3. Heya!

    Just wanted to let you know that the changes you made to the code worked EXCEPT changing tax_input to a name; tax_input expects ids. When I switched your code back to IDs, it worked fine! Thank you so, SO much for your help!!

    Just for anyone else's reference, here's the working code: http://pastie.org/1879622

    One question: can you elaborate on the RGFormsModel object? What is that?

    Thanks!

    --eric

    Posted 12 years ago on Monday May 9, 2011 | Permalink
  4. Eric,
    I am glad you got it working!

    The RGFormsModel is a class that handles all data access in Gravity Forms. It also has some helper methods used across the plugin.

    Posted 12 years ago on Monday May 9, 2011 | Permalink

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