Best way to reload POST data if there are form validation errors

72 views
Skip to first unread message

solo

unread,
Feb 11, 2017, 6:06:32 PM2/11/17
to Fat-Free Framework
I'm working on some simple forms with F3, and I'm wondering what the best way to re-load form data is in case there are form validation errors.

Currently my overall process is:
  • POST the form to my class.
  • Class validates the POST data.
  • If any error, send a message to the template system and reroute to the same page again.
I would typically use SESSION variables for this, however I think it may make more sense to simple set up a new variable, such as:

$this->f3->set('formRefill','POST');

Is this frowned upon for any reason?

Additionally, would I need to ensure that this is CLEARED/UNSET in my "afterroute" function?

Thanks for the help. 

ved

unread,
Feb 11, 2017, 6:31:26 PM2/11/17
to Fat-Free Framework
I personally use something like:

<input type="text" name="x" value="{{ isset(@POST.x) ? @POST.x : '' }}">

But i usually always submit to the same page and only reroute when successful so I'm not sure that works with your process.

solo

unread,
Feb 11, 2017, 9:13:20 PM2/11/17
to Fat-Free Framework
Hm, that's a good point, is there any benefit to submitting to the same page - i.e. using the same route and just processing the data if POST isset?

ved

unread,
Feb 11, 2017, 9:38:33 PM2/11/17
to Fat-Free Framework
Well, one benefit compared to your initial suggestion is surely simplicity. You can always still have a different method on your class to process the post even if using the same route.
Other than that, it may not always be the best method but I personally find it better for most crud type forms.

solo

unread,
Mar 4, 2017, 12:40:55 PM3/4/17
to f3-fra...@googlegroups.com
Deleted my note here, I overlooked something obvious =).
Reply all
Reply to author
Forward
0 new messages