Try this. It builds the form dynamically on the client and server so
you get to keep the benefits of SQLFORM (validation, etc):

def invite():
    fields = [Field('email',requires=IS_EMAIL())]
    for r in range(1, len(request.vars)):
        if 'email%s' % str(r) in request.vars.keys():
            fields.append(Field('email%s' %
str(r),requires=IS_EMAIL()))
    form = SQLFORM.factory(table_name='invited',*fields)
    submit = form.element('tr',_id='submit_record__row')
    if form.accepts(request.vars,session,keepvalues=True):
        request.flash = 'got it'
    add_row = XML(form.element('tr'))
    add_invite = INPUT(_type='button',_value='Add',
                       _onclick="var c = jQuery('input[type=\"text
\"]').size();"\
                                "jQuery('#%s').remove();var newrow =
'%s';"\
                                "newrow = newrow.replace(new
RegExp('email','g'),'email'+c.toString());"\
                                "jQuery('form:first
table').append(newrow + '%s');" % \
 
(submit['_id'],add_row,submit.xml()))
    return dict(form=form,add_invite=add_invite)



On Feb 26, 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 at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to