No, you should *not* give each form a unique name. Instead, use the code I
provided (though without specifying the "hidden" argument to SQLFORM, as
you will insert the hidden "id" field for each record's form directly in
the view). So, in the controller, you define only a single form with an
Also, don't do form.validate(session=None), as that will remove the CSRF
protection.
On Friday, September 18, 2015 at 7:37:48 AM UTC-4, Anthony wrote:
>
> No, you should *not* give each form a unique name. Instead, use the code
> I provided (though without specifying the "hidden" argument to
Thanks Annet, ill definitely will try,
I was trying to get away without having to write formstyles, since i need
control on the html output and it was a single post at a time.
I thought SQLFORM would be enough. but it isnt, ive hacked form.custom.end
so it renders the right id and formname
And this does work, which is very bad.
def example2():
rows = db(db.agencias).select()
#create as many forms as rows
forms = dict()
for row in rows:
forms[row.id] = SQLFORM(db.agencias, row.id).process()
fields = forms.itervalues().next().fields
if
No need for all this -- you can still use the method I proposed, creating
just a single form (and giving it an explicit name). As you build each form
in the view, just include a hidden "id" field and set its value to row.id
(no need to use the "hidden" argument to SQLFORM, as you will be adding
Hi Anthony. ye ive tried, tricked the view so it has unique form names but
on submission, if i call process, it wont pass validation. Im probably doin
it wrong but ive manage to get it working.
Ive decided to make a video out of this, so i can explain the problems im
having and how did i solve
What i was trying is easy, no ajax or js involved.
Something like this:
Each field is contained within an input and each row withtin a form with
several kinds of submits (update, delete or insert)
My doubts were:
Because i need that many forms as records i was wondering if i need to do
the
Hi Alfonso,
Seeing a picture of what you're trying to build, I wonder why you're not
using
SQLFORM.smartgrid as described in the book:
http://web2py.com/books/default/chapter/29/03/overview#Adding-grids
You can modify the grid in all kinds of ways:
By default, the formname for an update form includes the record ID, which
yields a unique formname for each record. The formname is the key used to
store the CSRF token in the session, so if you create a form with one name
but submit a form with a different name, the CSRF tokens won't match.
It looks like what i was missing is that the SQLFORM will perform an insert
or update depending on *its form name*, it wont matter if i explicit set a
record id when before its processed.
If the submmited form name is mytable/create it will perform an insert, but
i was passing an id that
Ok Niphlod i took your advise ive read the chapter again and i see what the
problem might be.
if id is not None the first time the form is created, the form does update
correctly without having to submit twice, but the tokens still dont match.
Is this the desired behaviour? The form works well
definitely not getting how self-submission works.. read the book first
if you want to fiddle with forms yourself.
tl:dr: you're selecting a record to edit BOTH before and after the form has
processed the actual submission.
On Tuesday, September 15, 2015 at 6:13:10 PM UTC+2, Alfonso Serra
Ive bought the book, ive read it and watched the massimo videos. ill read
it again in case im missing something, maybe i should use SQLFORM.grid() or
something.
ive used {{=form.custom.begin}} to write where that form is submitted and
{{=form.custom.end}} to get the token. If the action or
Start small: you're missing how forms work in self-submitting controllers
(which is the de-facto standard in pretty every framework)...
def testfunction():
#. this piece gets called when you render the form AND when you
submit it
form = SQLFORM() #... this creates the form
14 matches
Mail list logo