0

I try to pass the next form by clicking the 'submit' button (I checked the all 2 fields):

<form id='contact-form' name='contact-form' method='get' action='/3/'>
    <input type='checkbox' name='v[]' value='1'>
    <input type='checkbox' name='v[]' value='2'>
    <input type='submit'>
</form>

In my view I output all received variables (using Django framework):

@template
def view3( request ):
    print "request={0}".format( request.REQUEST )
    ...

I got only the last variable in output:

request={u'v[]': u'2'}

Is it something wrong with the snippet of html?

Additional Info. The html containing the form is in a frame on another html page.

3
  • I'm sorry, my answer was wrong I deleted it, but I have a suggestion, are you using single quotes in the real html or is just a copy paste error? It should be with double quotes Commented May 21, 2013 at 20:03
  • @PauloBu We can use any quotes we want - double or single. Commented May 21, 2013 at 20:52
  • 1
    Don't use field names like v[], that's a PHP-ism. Commented May 22, 2013 at 12:11

1 Answer 1

2

Python's dictionaries only allow one value per key, therefore Django offers a special type for this case, a QueryDict. To obtain a list of values coming from an input array, you need to call getlist on it:

v = request.GET.getlist('v')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.