Question

I am using http://dingyonglaw.github.com/bootstrap-multiselect-dropdown/#forms to display a dropdown with multiple check boxes.

<li>
  <label>
    <input type="checkbox" name="filters" value="first value">
    <span>First Value</span>
  </label>
</li>

<li>
  <label>
    <input type="checkbox" name="filters" value="second value">
    <span>Second Value</span>
  </label>
</li>

This is the resulting URL:

http://example.com/search?filters=first+value&filters=second+value

On Server side (bottle):

terms = unicode (request.query.get ('filters', ''), "utf-8")

will give me only "second value" and ignore "first value". Is there a way of collecting all the 'filters' values?

Was it helpful?

Solution

Use the request.query.getall method instead.

FormsDict is a subclass of MultiDict and can store more than one value per key. The standard dictionary access methods will only return a single value, but the MultiDict.getall() method returns a (possibly empty) list of all values for a specific key.

OTHER TIPS

Hey I had the same problem and figured out the solution

I'll write code that applies to your problem

HTML: (noted, I'm not super proficient here so there may be an error but the basic structure is correct). Here we want to setup a "form action" and use method=GET

<form action="/webpage_name" method="GET">
<li>
  <label>
    <input type="checkbox" name="filters" value="first value">
    <span>First Value</span>
  </label>
</li>
<li>
  <label>
    <input type="checkbox" name="filters" value="second value">
    <span>Second Value</span>
  </label>
</li>
<input type="submit" name="save" value="save">
</form> 

Python: The variable "all_filters" will take all the data from "filters" variable from bottle import request

@route('/webpage_name', method='GET')
def function_grab_filter():
    if request.GET.save:
        all_filters = request.GET.getall('filters')
        for ff in all_filters:
            fft = str(ff[0:]) # you might not need to do this but I had to when trying to get a number
            do soemthing....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top