On Saturday, August 3, 2013 2:41:35 PM UTC-4, Gökçen Eraslan wrote: > Hello, > > On 02-08-2013 00:54, Anthony wrote: > > I think you should be able to call form.process() in the view, though > it's > > probably a better idea to do this in the controller. Can you show your > code? > > > > I am planning to switch my old code from modpython to web2py. The > problem is I have a complex form and new inputs are added/removed > through jQuery. So I'm planning to write a Python function within the > view and reuse it as necessary. However, I do not know how to validate > these forms when they are submitted to controllers. Since the only way > for validation that I know, is to use FORM() helper in the controller > and call form.process().accepted. >
Again, you don't *have* to call form.process() in the controller -- you can call it in the view (though you probably shouldn't). However, if you want web2py to validate the form, you obviously have to create a form object for it to validate. There's nothing wrong with generating a form object in the controller for purposes of validation/database inserts but use completely custom HTML in the view -- as long as the HTML matches up with the form object DOM (i.e., same input variable names). Note, web2py includes a hidden _formname field, and optionally a hidden _formkey field (which you should use because it protects against CSRF attacks). Once you create the form in the controller, you can access those values via form.formkey and form.formname in order to insert them into your HTML (or just insert {{=form.hidden_fields()}} somewhere in your HTML form). Anthony -- --- 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/groups/opt_out.