Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Should I Create Separate Methods for Form Presentation and Processing in Controller?
  • I have a form that's view. I need to... 1) Present (aka display) it from controller,
    2) Process (aka submit) it from controller. For #1: http://pastie.org/1977002 , for #2: http://pastie.org/1977009 . Should I create separate methods for each of those actions?
    If yea, then how to call 2nd method if 1st is "add"?
    If nop, then how to detect that form is submitted (form can have post or get method)?
  • I have a couple of ways of doing this which I'll list below. It's worth it to note that I always redirect after processing to prevent resubmit by refresh, thus the confirmation of submit is given on a separate page or as a message on another page. 1. Simple, just couple of fields - never used somewhere else in the app: one method, which does display, validation & processing.
    2. A bit more complex: One method that does validation & display, the processing is done in a separate method but that is called from within the same method and execution is returned to that method once done.
    3. Larger systems: have validation & processing rules within the model with a generic page that loads views and tries saving it by using the model methods. Bottom line: I always submit to the same method, but how that method deals with the submission differs.
  • I did like this... Controller_News in classes/controller (for displaying news) and Controller_News_Add in classes/controller/news/add.php with methods action_index() for displaying form for news adding and action_process(), that checks for validation and call Model_News. Serious business!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion