0

Working thru the manual (4th ed), and just want to know what is considered the best way to code using helpers, should I them to build forms in the controller or the view.

My (very) limited experience i thought it would def be the latter... pg83

AtomicCrash
  • 81
  • 1
  • 5

1 Answers1

1

My (very) limited experience i thought it would def be the latter... pg83

By "the latter", do you mean the view? Because the examples on p. 83 of the book build the forms in the controller, not the view (of course, ultimately the form is serialized in the view).

In general, you should probably process the form in the controller (which is the norm). In order to process the form, though, you must first create it -- so it should be created in the controller as well.

For more on when and where to use HTML helpers in general, see here.

Community
  • 1
  • 1
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Thanks Anthony "kind of" makes sense. Following the MVC pattern i thought the form would be part of the "view" – AtomicCrash Aug 21 '12 at 20:54
  • Keep in mind, the form is not merely HTML or even a Python object that simply represents HTML. Rather, it is an object that encapsulates the default and submitted values, validators, CSRF token, etc., and knows how to validate itself (and insert its data into the db in the case of SQLFORM). So, its functionality is not strictly view related. You still have to insert it in the view so it can be serialized, and if you want to customize the visual display, you would do that in the view as well. So, the display aspects of the form are still handled in the view (for the most part). – Anthony Aug 21 '12 at 21:19
  • Ah ha! Thanks Anthony, great explaination – AtomicCrash Aug 23 '12 at 00:16