Support » Plugin: Gravity Forms + Custom Post Types » How to? One form with one taxonomy and multiple values.

  • Resolved Runamok81


    Is it possible to save multiple values to a taxonomy?

    I have Gravity Form with multiple single line text inputs.
    Each of these inputs has the “Save to Taxonomy” checkbox checked.
    They all point to the same Taxonomy, Authors.

    Upon save, only the last input field is saved to the taxonomy.
    Is there a way to associate ALL of the values to the taxonomy?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Bump.

    Just to be sure I am not asking something of CPT that is not possible, a follow up question…

    Does anyone know if the WP schema allows for a single post to have multiple values in a single taxonomy? That is, can I have one post that is a member of the taxonomy colors with the values red, blue, green?

    Hey man, I haven’t tried this (rarely use tag-style taxonomies), but I think the answer is you need to get users to enter their terms in a comma-delimited way rather than on multiple fields. Check out this screenshot from the plugin’s screenshots section:

    You need to use the “Enable enhanced user interface (?)” button in the field’s UI when editing the form.

    Another option is to use a hierarchical taxonomy and a multi-select or checkboxes field. Either way you shouldn’t be using the same taxonomy more than once. Ideally this plugin would stop you from doing that but logically what’s happening to you is what I’d expect.

    That got me moving in the right direction!
    If I check “save to taxonomy” and the “enhanced UI” buttons and then fill the box with some comma separated values, I can see that multiple (tag-style) values WILL populate to the same single taxonomy. Thanks Jeremy!

    Now that I know this method works, AND that I can’t have multiple fields saving to the same taxonomy, I realize that if I want to save multiple values to the same taxonomy it will have to be through a single input. Since I’m using multiple custom fields (single line text) to populate my taxonomy, I’m now trying to find a way to use a gform pre_submission_handler to concatenate my user inputs into a csv’d string and drop that into the “save to taxonomy” post value. I already do something similar in my functions.php for taxonomies that only get one value from the form. Note: All of this wouldn’t be needed to do this if the “save to taxonomy” box was available when using custom input types.

    Here is my code which copies a value from one gform field into another, which in my case copies the value from a custom input field and pastes it into the “save to tax” box. The last commented out line is where I’m stuck…

    /* Copies a value from one gform field into another. Used in combo with taxonomies to help build a search index
     * See here:
     * [Save to Taxonomy field] = [GF Custom Field]
    	add_action("gform_pre_submission_1", "pre_submission_handler");
    	function pre_submission_handler($form){
    		$_POST["input_77"] = $_POST["input_89"];
    		$_POST["input_92"] = $_POST["input_90"];
    		//$_POST["input_92"] = $_POST["input_90"]+$_POST["input_92"]+$_POST["input_92"];

    Long shot, but does any kind soul have any ideas on how to expand that code in a way which would string multiple $_POST values into a single csv’d $_POST value? If not, looks like I’m off to learn how/if PHP can cherry-pick values from an array and string them together…

    To back it up a bit, have you tried using your taxonomy with checkboxes or multi-select input types? This plugin supports both as far as I can tell and they would allow you to control the taxonomy terms while still allowing more than one choice.

    The only downfall is that hierarchical taxonomies are only supported by the dropdown solution, so if you need the hierarchy to be sorted/visible dropdown is your only option (that’s actually the problem I came here to solve, it’s not that hard with a few edits to the plugin).

    If you have a lot of items in your taxonomy you might way to set overflow:auto; and a height value on the container for the checkboxes so that it’s a scrolling box instead of a neverending list.

    That would be an option if I was using standard fields, but I’m actually using custom input types and those buggers don’t have the “save to taxonomy” checkbox! To workaround this, I’ve been lateraling the custom field’s input value into a standard field via pre_submission_handler. Since I’ve had success with this, I think I could expand it to work with multiple values.

    Well that was easier than expected! Just use PHPs concatenate and throw some commas in there. Whoo ha!
    $_POST["input_42"] = $_POST["input_42"].",".$_POST["input_132"].",".$_POST["input_133"].",".$_POST["input_134"].",".$_POST["input_135"].",".$_POST["input_136"];

    Thanks for pointing me in the right direction Jeremy!

    [Topic marked as Resolved]

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to? One form with one taxonomy and multiple values.’ is closed to new replies.