Forums

[resolved] Sending an array of values to QMT? (4 posts)

  1. JsonB123
    Member
    Posted 1 year ago #

    I'm trying to get input from checkboxes (tags, or any other custom taxonomy) to get taken in and parsed with QMT plugin. I have the checkboxes set up, but of course when I give them all the appropriate name, only the last set checkbox gets sent:

    <input type="checkbox" name="tag" value="tag-one" />

    I also tried doing it as you would with an array

    <input type="checkbox" name="tag[]" value="tag-one /> and so on so that they all get taken in. This also doesn't work.

    How do I set this up properly so that I can send data to the Search where if more than one checked box were selected the query would be as follows, in the URL:

    http://myblog.com/?tag=tag-one+tag-two

    Thanks!

  2. JsonB123
    Member
    Posted 1 year ago #

    Bumping the question...just in case anyone has any idea (I mis-labled the tags on this post originally).

  3. scribu
    Member
    Posted 1 year ago #

    How do I set this up properly so that I can send data to the Search where if more than one checked box were selected the query would be as follows, in the URL:

    http://myblog.com/?tag=tag-one+tag-two

    That's something you could achieve with a little bit of jQuery (only tested in Firefox):

    jQuery('#myform').submit(function() {
        var $form = $(this),
            values = [];
    
        // remove checkboxes, while keeping their values
        $(':checked').each(function() {
            values.push( $(this).remove().val() );
        });
    
        // create a new text input with the concatenated value
        $form.prepend( $('<input>').attr({
            'type': 'text',
            'name': 'tag',
            'value': values.join('+')
        }) );
    });

    Replace #myform with your own selector. Also, you might want to replace the :checked selector with something more specific.

  4. JsonB123
    Member
    Posted 1 year ago #

    Good point. I was hoping not to resort to requiring JS for this...but I suppose that this is one of those cases where it is easier to do that than try to hack the PHP functionality of wordpress.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic