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 wrote:
>
> I have to submit the form twice in order to update a record,
> sometimes request.post_vars['id'] returns a list without changing the view
> if i perform rows = db(db.agencias).select() it queries the database twice.
> Should i report these behaviours as bugs or am i doin something wrong?
>
> Ive compared the formkey with the session key by throwing them into the 
> view
> and they doesnt match when i visit the page but they does if i view the 
> page's source code,
> i have to submit the form once so they match
>
> formkey = form.formkey
> sessionkey = session.items()[0][1][0]
>
> This is the form displayed for the first time using custom.begin and 
> custom.end. 
> It doesnt have any links, css, js neither any image is just plain html 
> text.
>
> <html>
> <head>
>   <title>Myapp</title>
> <style>
>     table{width: 500px; border-spacing: 0}
>     td{width:100%; border: 0px solid black;}
>     table td{width: 100px}
>     td input {width: 100%}
> </style>
> </head>
> <body>
> <p>welcome to agencies</p>
> <table>
>     <tr>
>         <td>id</td>
>         <td>agencia</td>
>         <td>precio</td>
>         <td>Actions</td>
>     </tr>
>     <tr>
>         <td colspan="4">  
>             <form action="#" enctype="multipart/form-data" method="post">
>             <table>
>                 <tr>
>                     <td><input name="id" value="1" type="text"></td>
>                     <td><input name="agencia" value="traveltour" 
> type="text"></td>
>                     <td><input name="precio" value="234.0" 
> type="text"></td>
>                     <td><input value="update" type="submit"></td>
>                 </tr>
>             </table>
>             <div style="display:none;"><input name="_formkey" 
> value="bb23ab13-c589-4b39-a2a0-6bab13d764d8" type="hidden"><input 
> name="_formname" value="agencias/create" type="hidden"></div></form>
>         </td>
>     </tr>
>     
> </table>
> <p>formkey:bb23ab13-c589-4b39-a2a0-6bab13d764d8</p>
> <p>sessionkey:463dee54-ca64-4c83-98f3-89e01a03f362</p>
> <div id="link64_vdp_tabid" style="display:none;">1144</div></body></html>
> </body>
> </html>
>
> controller:
> def index():
>    
>     id = request.post_vars['id']
>     print id
>
>     if isinstance(id, list): 
>         print id
>         id = id[0]
>
>     record = db.agencias[id]
>     print "vars", request.post_vars, id, record
>     
>     
>     form = SQLFORM(db.agencias, record)
>     
>     if form.process().accepted:
>         print "all good, proceed"
>         response.flash = "all good, proceed"
>     elif form.errors:
>         print "errors in form"
>         response.flash = "errors in form"
>     else:
>         response.flash = "welcome to agencies"
>
>     formkey = form.formkey
>     sessionkey = session.items()[0][1][0]
>
>     rows = db(db.agencias).select()
>     return locals()
>

-- 
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.

Reply via email to