Where do you see that snippet of code?

You've got a few problems.

You need to return the form in the dict:

def display_manual_form():
   form = SQLFORM(db.person)
   if form.accepts(request.vars, formname='test'):
       response.flash = 'form accepted'
   elif form.errors:
       response.flash = 'form has errors'
   else:
       response.flash = 'please fill the form'
   return dict(form=form)

Then, make sure name your view the same as the function name so that
web2py knows which view to show.

=== display_manual_form.html ===
{{extend 'layout.html'}}
{{=form}}

If you don't want all of the fields in db.table to display, you can
either set some fields to writable/readable=False or create custom
forms in your view. There are two options outlined here:
http://web2py.com/book/default/chapter/07#Custom-forms

As you can see, the more customized you make it, the less help you get
from web2py. Try to use web2py's features as much as possible in the
beginning. Then once you are comfortable, you can customize as
desired.



On Mar 10, 2:11 pm, DenesL <denes1...@yahoo.ca> wrote:
> The form.accepts in the controller checks the fields using their
> validators.
>
> The error messages you have to handle yourself in your custom form.
> For an example see:http://web2py.com/book/default/chapter/07#Hide-Errors
>
> On Mar 10, 4:33 pm, Pystar <aitoehi...@gmail.com> wrote:
>
>
>
>
>
>
>
> > So how do I design my forms manually and still have it display error
> > messages and use validators?
>
> > On Mar 10, 10:25 pm, DenesL <denes1...@yahoo.ca> wrote:
>
> > > Because the code to show those errors is in the form created by
> > > SQLFORM and that form is neither being returned nor displayed in the
> > > view.
>
> > > On Mar 10, 4:00 pm, Pystar <aitoehi...@gmail.com> wrote:
>
> > > > tried this snippet of code from the web2py book, but it doesnt work
> > > > the way I feel it should
>
> > > > def display_manual_form():
> > > >    form = SQLFORM(db.person)
> > > >    if form.accepts(request.vars, formname='test'):
> > > >        response.flash = 'form accepted'
> > > >    elif form.errors:
> > > >        response.flash = 'form has errors'
> > > >    else:
> > > >        response.flash = 'please fill the form'
> > > >    return dict()
>
> > > > {{extend 'layout.html'}}
> > > > <form>
> > > > <ul>
> > > >   <li>Your name is <input name="name" /></li>
> > > > </ul>
> > > >   <input type="submit" />
> > > >   <input type="hidden" name="_formname" value="test" />
> > > > </form>
>
> > > > On submission, if there are errors in the form, it doesnt display any
> > > > error messages. why is this so?

Reply via email to