Yes. You can also do

def index():
     form=FORM(INPUT(_name='test', requires=IS_NOT_EMPTY()))
     if form.accepts(request.vars,session=None,formname='test'):
         response.flash='form accepted'
     elif form.errors:
         response.flash='form has errors'
     else:
         response.flash='please fill the form'
     return dict()


 <form>
 {{=INPUT(_name='test',_class='...')}}
 <input type='submit' />
 <input type='hidden' name='_formname' value='test' />
 </form>

or (latest trunk)

{{=form.custom.begin}}
{{=form.custom.widget.test}}
{{=form.custom.submit}}
{{=form.custom.end}}

Massimo


On Jun 17, 10:47 am, carlo <syseng...@gmail.com> wrote:
> sorry Massimo to insist upon this but I would like to get it clear.
> I understand this: if you want to validate one field you have to put
> that field in the FORM() of the controller, this duplication is the
> trade off to get validation.
>
> So this is the way to preserve validation:
>
> Controller:
>
> def index():
>     form=FORM(INPUT(_name='test', requires=IS_NOT_EMPTY()))
>     if form.accepts(request.vars,session=None,formname='test'):
>         response.flash='form accepted'
>     elif form.errors:
>         response.flash='form has errors'
>     else:
>         response.flash='please fill the form'
>     return dict()
>
> View:
>
> <form>
> <input name='test' type='text' />
> <input type='submit' />
> <input type='hidden' name='_formname' value='test' />
> </form>
>
> thanks
> carlo
>
> On 17 Giu, 17:07, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > in your code, the form that accepts is form=FORM() and it contains no
> > fields. No variable is transferred from request.vars to form.vars.
> > There are no errors because there are no fields.
>
> > The {{=INPUT(....)}} is the view get serialized when the form is
> > displayed but it is not used by accept because it is not part of the
> > form.
>
> > While you can use this syntax to build custom forms, you cannot use
> > this syntax to process forms.
>
> > Massimo
>
> > On Jun 17, 5:22 am, carlo <syseng...@gmail.com> wrote:
>
> > > From the manual there is no reason this should not work, but the form
> > > is accepted even with the empty field. Why? Thank you
>
> > > carlo
>
> > > controller:
>
> > > def index():
> > >     form=FORM()
> > >     if form.accepts(request.vars,session,formname='test'):
> > >         response.flash='form accepted'
> > >     elif form.errors:
> > >         response.flash='form has errors'
> > >     else:
> > >         response.flash='please fill the form'
> > >     return dict()
>
> > > view:
>
> > > {{extend 'layout.html'}}
> > > <form>
> > > <input name='text' type='text'/>
> > > {{=INPUT(_name='prova',_type='text',requires=IS_NOT_EMPTY())}}
> > > <input type='submit'/>
> > > <input type='hidden' name="_formname" value="test"/>
> > > </form>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@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