maybe something like this would work :
if idToEdit :
record = db(db.langResource.id==idToEdit)
sqlForm = SQLFORM(db.langResource, record) # update existing
else :
sqlForm = SQLFORM(db.langResource) # create new
if sqlForm.process().accepted:
response.flash = 'New resource added.'
elif sqlForm.process().accepted:
response.flash = 'Resource modified.'
elif sqlForm.errors:
response.flash = 'Form has errors.'
else:
response.flash = 'Please fill out the form.'
return sqlForm
On Thu, Apr 17, 2014 at 9:11 PM, Sharon Correll <[email protected]>wrote:
> I am a web2py newbie, and I'm sure this is a very basic question, but I
> haven't found a post that addresses it exactly.
>
> I am trying to create a form that modifies an existing record. My code,
> which is modeled after stuff I saw in the tutorial, looks like:
>
> if idToEdit :
> record = db.langResource(idToEdit)
> sqlForm = SQLFORM(db.langResource, record) # update existing
> else :
> sqlForm = SQLFORM(db.langResource) # create new
>
> if sqlForm.process(session=None,
> formname="langResource/create").accepted:
> response.flash = 'New resource added.'
> elif sqlForm.process(session=None,
> formname="langResource/modify").accepted:
> response.flash = 'Resource modified.'
> elif sqlForm.errors:
> response.flash = 'Form has errors.'
> else:
> response.flash = 'Please fill out the form.'
> return sqlForm
>
> When idToEdit is set to something, the resulting form is nicely populated
> with the values of the existing record. However, when I press Submit, a new
> record is added with the changes, and with a new unique ID. The old record
> is still there.
>
> I had originally tried to create the HTML by hand, so I could customize
> it, and had the same problem, so I thought my HTML was missing something.
> But using the SQLFORM directly does the same thing.
>
> I did see this bit in the HTML: <input name="id" type="hidden" value="5"
> /> - and wondered if that is the magic bit that makes it know that it is
> supposed to update an existing record. But if so it doesn't seem to be
> working.
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.