Unfortunately you will not be able to "add" fields when using FORM. You will have to iterate over the request.vars manually.
-Thadeus On Fri, Feb 26, 2010 at 3:59 PM, minh <mdn0...@gmail.com> wrote: > I forgot to mention, the form loads fine... I get the error on submit. > > On Feb 26, 1:58 pm, minh <mdn0...@gmail.com> wrote: >> I have something like this: >> >> form = FORM('Emails:', BR(), >> INPUT(_name='email', >> requires=IS_NULL_OR(IS_EMAIL())), BR(), >> INPUT(_name='email', >> requires=IS_NULL_OR(IS_EMAIL())), BR(), >> INPUT(_name='email', >> requires=IS_NULL_OR(IS_EMAIL())), BR(), >> INPUT(_name='email', >> requires=IS_NULL_OR(IS_EMAIL())), BR(), >> INPUT(_name='email', >> requires=IS_NULL_OR(IS_EMAIL())), BR(), >> 'Message:', BR(), >> TEXTAREA(_name='message'), BR(), >> INPUT(_type='submit', _value='Invite')) >> >> However, it seems to crash if I have multiple elements named 'email'. >> It works fine if I name them email1, email2, etc. This is the error: >> >> Error traceback >> >> Traceback (most recent call last): >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \restricted.py", line 173, in restricted >> exec ccode in environment >> File "C:/Documents and Settings/minh/My Documents/InvestP2P/ >> applications/investp2p/controllers/loans.py", line 209, in <module> >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \globals.py", line 96, in <lambda> >> self._caller = lambda f: f() >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \tools.py", line 1848, in f >> return action(*a, **b) >> File "C:/Documents and Settings/minh/My Documents/InvestP2P/ >> applications/investp2p/controllers/loans.py", line 200, in >> invite_lenders >> if form.accepts(request.vars, session): >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \html.py", line 1267, in accepts >> status = self._traverse(status) >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \html.py", line 449, in _traverse >> newstatus = c._traverse(status) and newstatus >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \html.py", line 456, in _traverse >> newstatus = self._validate() >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \html.py", line 1074, in _validate >> (value, errors) = validator(value) >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \validators.py", line 2055, in __call__ >> return self.other(value) >> File "C:\Documents and Settings\minh\My Documents\InvestP2P\gluon >> \validators.py", line 774, in __call__ >> match = self.regex.match(value) >> TypeError: expected string or buffer >> >> On Feb 26, 1:02 pm, Thadeus Burgess <thade...@thadeusb.com> wrote: >> >> > if they all have the same name you will receive it as a list in >> > request.vars as the name >> >> > You will need to use jQuery to dynamically add more fields. >> >> > Also, you could use a textarea instead and have them press enter, and >> > then split the string on '\n' >> >> > So considering the following html >> >> > <input type="text" name="hi" id="hi1" value="hello" /> >> > <input type="text" name="hi" id="hi2" value="world" /> >> >> > This will be serialized into >> >> >www.example.com?hi=hello&hi=world >> >> > Which will be parsed by web2py into request.vars like so. >> >> > request.vars.hi = ['hello', 'world'] >> >> > -Thadeus >> >> > On Fri, Feb 26, 2010 at 2:50 PM, minh <mdn0...@gmail.com> wrote: >> > > Hi, >> >> > > I want to make a page where users can enter e-mails to send an invite. >> > > There will be an array of input boxes (1 e-mail each box) and a send >> > > button. >> >> > > I was wondering what the best way to generate the form dynamically >> > > was... in case the user wanted to add more e-mails. >> >> > > Also, is there a way to iterate through the form elements so I don't >> > > have to worry about number/name of input fields? >> >> > > Thanks, >> > > Minh >> >> > > -- >> > > You received this message because you are subscribed to the Google >> > > Groups "web2py-users" group. >> > > To post to this group, send email to web...@googlegroups.com. >> > > To unsubscribe from this group, send email to >> > > web2py+unsubscr...@googlegroups.com. >> > > For more options, visit this group >> > > athttp://groups.google.com/group/web2py?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.