On Wednesday, November 1, 2017 at 8:36:49 AM UTC-7, runr...@gmail.com wrote: > > 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. > > " >
Did you have a request.args(0)? The redirect you mention seems to be because of that. Just above the portion of the book you quote, there's this: You can modify the controller of the previous example so that when we pass an additional integer argument in the URL path, as in: 1/test/default/display_form/2 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.