I have scrapped the controller I was using because it wasn't working but it
was something like this
def display_form():
*record = alpha.person(request.args(0)) or redirect (URL('index'))*
form=SQLFORM(alpha.person,* record)*
if form.process(keepvalues=True).accepted:
response.flash = "Thank you for filling out the form."
redirect(URL('thank_you'))
elif form.errors:
response.flash = "form has errors"
else:
response.flash = "please fill out the form"
return dict(display_form=form)
I was using the code from this section of the book
"and if there is a record with the corresponding id, the SQLFORM generates
an UPDATE/DELETE form for the record:
1
2
3
4
5
6
7
8
def display_form():
record = db.person(request.args(0)) or redirect(URL('index'))
form = SQLFORM(db.person, record)
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)
Line 2 finds the record and line 3 makes an UPDATE/DELETE form. Line 4 does
all the corresponding form processing.
An update form is very similar to a create form except that it is
pre-populated with the current record and it previews images. By default
deletable
= True which means the update form will display a "delete record" option.
"
On Tuesday, October 31, 2017 at 12:53:15 PM UTC-7, Dave S wrote:
>
>
>
> On Tuesday, October 31, 2017 at 11:54:59 AM UTC-7, R U wrote:
>>
>> I am curious of how to override an existing record in a database via a
>> form.
>>
>> Take for example a simple input of
>> db = DAL('sqlite://storage.sqlite')
>> db.define_table('person',
>> Field('email', requires=IS_EMAIL()),
>> Field('Your_Zipcode', requires=IS_NOT_EMPTY()),
>>
>> If the same email address is entered that was previously in the db I get
>> 2 records of the same e-mail.
>>
>> I don't want to go through the built in auth. I want to keep it simple.
>> If the person has to change his/her address s/he can simply fill in the
>> form and it overrides the existing record.
>>
>> I get redirected to index when I use the following in the controller.
>>
>> http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-and-insert-update-
>>
>>
>> What am i missing?
>>
>>
> Please show your controller function.
>
> In code that I have in front of me, I use update_or_insert() without a
> form. At home, I think I have an SQLFORM with an example of
> update_or_insert, and I don't remember any issues, but I can't show it to
> you from here.
>
> /dps
>
>
--
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.