Here is how you do it (this is explaned in the book in some detail):

For example:

#in model

    db.define_table('dog',SQLField('name',default=''))

    def custom(table):
        import uuid
        formkey=session['_formkey[%s]' % table]=str(uuid.uuid4())
        return DIV(INPUT(_name='_formname',_value=str(table)),
                    INPUT(_name='_formkey',_value=formkey)))

#in controller

    def index():
         form=SQLFORM(db.dog)
         if form.accepts(request.vars,session):
               pass # do something
         elif form.errors:
               pass  # do something else
        return dict(form=form)

#in the view build your custom form in HTML

    <form>
    {{=custom(db.dog)}}
    <input name="name" value="{{=form.vars.name or
db.dog.name.default}}" />
    <input type="submit">
    </form>

Notice you need to add  {{=custom(db.dog)}} in the form.

Massimo

On Oct 28, 9:06 pm, Iceberg <[EMAIL PROTECTED]> wrote:
> Hi Massimo,
>
> Thanks for the quick response, but the point is about customizing the
> layout. For example, I want the "customer information" and "agent
> information" are displayed in separated row, it looks better. I did it
> by this:
>
> def add():
>   form=FORM(TABLE(
>     TR("Customer Name:", INPUT(...), "Customer Addr", INPUT(...),
> "Customer Phone", INPUT(...) ),
>     TR("Agent Name:", INPUT(...), "Agent Addr", INPUT(...), "Agent
> Phone", INPUT(...) ),
>     ......
>
> Now, the question is, how to reuse the same layout in a edit()
> controller? This way loses the layout.
>
> def edit():
>   from=SQLFORM(db.orders, a_record)
>
> Any ideas?
>
> On Oct29, 1:55am, mdipierro <[EMAIL PROTECTED]> wrote:
>
> > SQLFORM make a FORM from a database table.
> > you can make a form manually:
>
> > form=FORM(TABLE(TR(TD(...))))
>
> > or you can use a factory (to pretend you have a database table
>
> > from gluon.sqlhtml import form_factory
> > form=form_factory(SQLField('name','string',requires=IS_NOT_EMPTY(),label='Y 
> > our
> > Name'),SQLField('birth','date'))
>
> > they both work like a SQLFORM but the former does not handle automatic
> > file upload, the latter does.
>
> > On Oct 28, 12:49 pm, Iceberg <[EMAIL PROTECTED]> wrote:
>
> > > Hi, Massimo,
>
> > > I start learning web2py for a week and it is already addictive. :-)
> > > Thank you very much.
>
> > > Now I encounter a tricky problem: Can SQLFORM accept TABLE(...) as its
> > > first parameter?
>
> > > The problem description might be clear, but not its background. So I
> > > gonna explain some more.
>
> > > My application is an sales order management system, which has a
> > > complicated "orders" table. Instead of using the default view layout
> > > generated by the simple code as "form=SQLFORM(db.orders)" in
> > > controller add(), I manually build a form in this way, to customize
> > > the layout:http://mdp.cti.depaul.edu/AlterEgo/default/show/128
>
> > > But later when I want to implement an update page and a view page for
> > > the old orders, I find out that there is no obvious simple way to
> > > reuse the layout I have just built.  Followed my intuition, I tried
> > > this:
> > >   form=SQLFORM( TABLE( TR(...bla bla, copied and pasted from add()
> > > controller...) ),  one_order_record )
> > > however, it does not work.
>
> > > Do I have to create a edit.html view and arrange every components
> > > manually in HTML level?  That is labouring, and the worse is that can
> > > not reuse the effort in my add() controller.
>
> > > Any suggestion? Thanks in advance!
>
> > > Sincerely,
> > >              Iceberg, 2008-Oct-29, 01:18(AM), Wed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to