WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms + Custom Post Types
Custom Taxonomy as checkboxes with checked values (4 posts)

  1. sanzweb
    Member
    Posted 2 years ago #

    Absolutely fantastic addon to GF ... makes working with GF that much easier.

    Just need a little help with something that is doing my head in and I can't seem to find a solution that works.

    I have a GF user registration form that outputs terms from a custom user taxonomy (Retailer Categories) as checkboxes and they are showing up fine.

    When submitting the form I'm expecting the user to be registered as required (which is what is happening as I get the email and the user shows up under Users) however I'm also expecting the selected Retailer Category terms to be set for the user which does not seem to be happening.

    Am I asking too much out-of-the-box? Do I need custom code somewhere that will link the selected terms with the user? If so what?

    Also when creating an "edit" form is there a way to output the same Retailer Category checkboxes but have the terms saved previously, "selected" using your plugin? I've tried to piece together bits of code from both GF forums and elsewhere with no luck.

    Any help or guidance would be greatly appreciated.

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

  2. bradvin
    Member
    Plugin Author

    Posted 2 years ago #

    Hi there,

    I have never tried to do this with a user before, but doing a quick search returned this, which might help you : http://wordpress.org/support/topic/applying-custom-taxonomies-to-user-profiles?replies=9

    Unfortunately, you will have to do some coding to get this working, as it will not work out of the box.

    regarding the edit form for a user, you might be better off using a plugin built for this type of thing. Something like : http://wordpress.org/extend/plugins/profile-builder/

  3. sanzweb
    Member
    Posted 2 years ago #

    Thanks Brad ... cheers for those links. I'll check them out shortly.

    Actually just now I've managed to solve at least part of my issue where I needed to show the terms as checkboxes and show the ones selected by the user:

    function selected_checkboxes($form){
    	global $current_user;
    	get_currentuserinfo();
    
        $choices = array();
        $inputs = array();
    	$args = array( 'hide_empty' => 0, 'taxonomy'=> 'retailer_category'); // change 'retailer_category' to your custom taxonomy
        $categories = get_categories($args);
    
    	$i = 1;
    	foreach ($categories as $category) {
    		$field_id = "8.".$i; /// change the 8 to whatever your field ID is
    		array_push($choices, array("text" => $category->cat_name, "value" => $category->cat_name, "isSelected" => (is_object_in_term( $current_user->ID, 'retailer_category', $category ) ) ? true : false )); // change 'retailer_category' to your custom taxonomy
    		array_push($inputs, array("label" => $category->cat_name, "id" => $field_id));
    
    		$i++;
    	}
    
        foreach($form["fields"] as &$field){
            //change the 8 to whatever your field ID is
            if($field["id"] == 8){
                $field["choices"] = $choices;
                $field["inputs"] = $inputs;
            }
        }
    
        return $form;
    }
    // filtering form ID 6 - change 6 to your form ID
    add_filter("gform_pre_render_6", 'selected_checkboxes');
    add_filter("gform_admin_pre_render_6", 'selected_checkboxes');

    Now to resolve the saving of the taxonomy terms to the user profile!!

    Thanks again.

  4. Mark
    Member
    Posted 1 year ago #

    Now to resolve the saving of the taxonomy terms to the user profile!!

    Hi, take a look at this solution:
    http://wordpress.org/support/topic/plugin-gravity-forms-custom-post-types-custom-user-taxonomies?replies=3#post-3038896

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic