request.vars[key] is always a string or a list of string (for multiple and 
checkboxes).
form.vars[key] is the the output of form validators on request.vars[key]. 
Validators are filters. Some of them like IS_INT_IN_RANGE do some parsing. 
IS_LIST_OF(...) for example always transforms the input into a list, which 
is what you suggested.

On Friday, 28 September 2012 21:39:40 UTC-5, MichaelF wrote:
>
> Makes sense; thanks. Posting a list on multi-selects would be a help, but 
> there's still the other problem you mentioned (other input types). I've 
> written code to try to take this into account by always converting the 
> value.
>
> Any thoughts on why sometimes the value comes across as an int, other 
> times as a string?
>
> Michael
>
> On Friday, September 28, 2012 7:01:44 PM UTC-6, Massimo Di Pierro wrote:
>>
>> Good question.
>>
>> The issues is the following. When an HTML form is submitted with one 
>> variable (a)  the query_string contains ?a=value. If it is submitted with 
>> two values, the query string contains ?a=value&a=other.
>>
>> When web2py (or any other framework) parses the query_string it may 
>> find ?a=value or ?a=value&a=other but it does not know if the variable 
>> comes from a normal input, a select, a multiple select, or checkboxes.
>>
>> Different frameworks take the same approach. Web2py parses ?a=value into 
>> request.vars.a='value' and ?a=value&a=other into 
>> request.vars.a=['value','other']. 
>>
>> Other frameworks do what you suggest and always use a list: ?a=value into 
>> request.vars.a=['value'] but the drawback is that they always do it even 
>> for regular input fields (<input name="a"/>). If we were to do it we would 
>> have lots more request.vars.a[0] everywhere.
>>
>> The web2py solution is a compromise, as many other design decisions are.  
>>
>> Massimo
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Friday, 28 September 2012 17:33:18 UTC-5, MichaelF wrote:
>>>
>>> I have a form with a multi-select. If I choose one value and submit, the 
>>> value is set in request.vars.xxx as a single integer (e.g., 2). If I choose 
>>> more than one value and submit I get a list of string values (e.g., ['1', 
>>> '5']). If I select no values I get None.
>>>
>>> Expected? Why the inconsistency? Or am I doing something wrong? Why not 
>>> ['2'], ['1', '5'], and []? That's consistent, orthogonal, etc.
>>>
>>> Thanks.
>>>
>>

-- 



Reply via email to