-1

I have a form, that users have to fill out with their informations. The theme I am using, had this to be a select. I changed it to multi select, as we needed people to be able to select multiple values.

However, after some user testing, we found that many did not know how to select multiple values in a selectbox. So I thought it would be better to make them checkboxes. I've been trying to figure out exactly how I could do that, but I can't seem to figure out how to do this.

<div class="form-option property-type-field-wrapper">
<label for="type"><?php _e( 'Useage', 'framework' ); ?></label>
<span class="selectwrap">
    <select multiple name="type[]" id="type" class="src_select">
        <?php
        if ( inspiry_is_edit_property() ) {
            global $target_property;
            edit_form_hierarchical_options( $target_property->ID, 'property-type' );
        } else {
            ?>
            <?php
            /*
             * Property Type Terms
             */
            $property_types_terms = get_terms( array(
                    'taxonomy'   => "property-type",
                    'orderby'    => 'name',
                    'order'      => 'ASC',
                    'hide_empty' => false,
                    'parent'     => 0
                )
            );
            generate_id_based_hirarchical_options( "property-type", $property_types_terms, - 1 );
        }
        ?>
    </select>
</span>

Anyone who think they might be able to give me a hint?

  • how is it wordpress specific? this seems a generic PHP question.... – Mark Kaplun May 8 '17 at 12:34
  • It might be, I just thought it would fit here, as I need it for Wordpress. – Beyond55 May 8 '17 at 12:43
1

Use the following function to make check-boxes for taxonomies:

function get_terms_chekboxes($taxonomies, $args) {
    $terms = get_terms($taxonomies, $args);
    foreach($terms as $term){
        $output .= '<label for="'.$term->slug.'"><input type="checkbox" id="'.$term->slug.'" name="'.$term->taxonomy.'" value="'.$term->slug.'"> '.$term->name.'</label>';
    }
    return $output;
}

echo get_terms_chekboxes('country', $args = array('hide_empty'=>true));

Hope this will help you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.