You've given the same name to three fields ('item[]'). web2py treats that as 
one field, so it puts all the values submitted in those fields into a single 
list to represent the value of the field. When an error is returned, web2py 
populates the form with the previously submitted values, so it is populating 
each of the item[] fields with the list of values submitted. Since there are 
three fields, it should actually be ['','',''] (the empty quotes would be 
replaced with actual values if any items were submitted with the form).

Is the 'items[]' field a list:string field? Why does the name have '[]' at 
the end of it? What does your DB model look like?

Anthony

On Wednesday, September 28, 2011 1:18:35 AM UTC-4, Joseph Jude wrote:
>
> Hi all,
> I have the below form (leaving out non-essential code)
>
> form = FORM(
> DIV(
> UL(
> SPAN(LABEL('Name:')),
> SPAN(INPUT(_type="text", _name="name", requires=IS_NOT_EMPTY()))),
> DIV(
> LABEL("Items:"),
> UL(
> SPAN(INPUT(_type="text", _name="items[]")), 
> SPAN(INPUT(_type="text", _name="items[]")), 
> SPAN(INPUT(_type="text", _name="items[]"))
> ))
> DIV(
> INPUT(_type="submit", _value="Create My List"),
> _class="submitbtn button")
> ))
> if form.accepts(request.vars, session):
> <rest of code>
> If this form is submitted with values the form values are written into the 
> databases. No problem. However, if it is submitted with an empty first field 
> (name), the the fields _name="items[]" are filled with values ['', ''] when 
> errors are flashed on the screen. I am not able to find why it happens and 
> also how to fix it. (there is a reason why I use the _name="items[]" - user 
> should be able to add as many items as possible at the client side). Any 
> clues and solution is appreciated. Thank you.
> Joseph
>

Reply via email to