The problem is the use of 'id' in the vars. What happens is that the form already has an 'id' field, although it is hidden it is still being sent back on submit, and then you add another 'id' in the vars so you end up with two, hence '|1|1|'.
To fix just use a variable name that is not in the form. On Dec 13, 5:38 pm, Seamon <[email protected]> wrote: > Hi, > > I've just experienced strage behaviour while using SQLFORM to update > records > in MySQL DB. The code is pretty basic (see below), just a little > cookbook application > and this part was ment to edit the recipe. First all seemed ok - the > form was displayed > as specified, but after submitting the changes I kept getting error > like this: > ValueError: invalid literal for int() with base 10: '|1|1|' > > Where the |1|1| was clearly connected to the record id. For some > reason the form.accept > was ignored and the whole result from the form submit came in as an > request (so it contained an id > but it was '|1|1|') and that was the problem. Apparently it can be > fixed with some type checking, but > it shouldn't by working like this as far as I know. Any idea why this > happens? > > DB Table: > cbook.define_table ('recipe', > Field ('Food_Name','string',length = 40), > Field ('id_author','integer',default = -1), > Field ('creation_date','date'), > Field ('suroviny','text'), #resources > Field ('popis','text'), #info > Field ('postup','text'), #recipe > Field ('verejny','boolean') #public > ) > Code: > def edit_recipe(): > if session.authorized: > > id = request.vars.id > record=cbook(cbook.recipe.id==id).select() > > form = SQLFORM (cbook.recipe,submit_button='Uloz > zmeny',record=record[0],showid=False,fields = > ['Food_Name','popis','suroviny','postup','verejny'] ) > > if form.accepts (request.vars,session): > response.flash = 'Recipe updated' > redirect(URL(r=request,c='recipes',f='edit_recipe',vars = > {'id':id})) > > return dict (form=form,id=id)

