WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms + Custom Post Types
[resolved] How to? One form with one taxonomy and multiple values. (8 posts)

  1. Runamok81
    Member
    Posted 1 year ago #

    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?

    Thanks!

    http://wordpress.org/extend/plugins/gravity-forms-custom-post-types/

  2. Runamok81
    Member
    Posted 1 year ago #

    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?

  3. Jeremy Clarke
    Member
    Posted 1 year ago #

    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:

    http://s.wordpress.org/extend/plugins/gravity-forms-custom-post-types/screenshot-6.png?r=653665

    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.

  4. Runamok81
    Member
    Posted 1 year ago #

    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: http://www.gravityhelp.com/forums/topic/how-to-populate-a-hidden-field-with-een-other-field#post-81974
     * [Save to Taxonomy field] = [GF Custom Field]
     */
    	add_action("gform_pre_submission_1", "pre_submission_handler");
    	function pre_submission_handler($form){
    		//reason
    		$_POST["input_77"] = $_POST["input_89"];
    		//product
    		$_POST["input_92"] = $_POST["input_90"];
    		//manufacturers???
    		//$_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...

  5. Jeremy Clarke
    Member
    Posted 1 year ago #

    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.

  6. Runamok81
    Member
    Posted 1 year ago #

    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.

  7. Runamok81
    Member
    Posted 1 year ago #

    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!

  8. Runamok81
    Member
    Posted 1 year ago #

    [Topic marked as Resolved]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic