开发者

Invalid Form Submissions-- what to do with them?

开发者 https://www.devze.com 2022-12-18 03:24 出处:网络
I\'ve been doing a lot of reading lately about best practices when it comes to Web App design. My language of expertise is PHP/MySQL. When creating an MVC architecture for an application I\'m developi

I've been doing a lot of reading lately about best practices when it comes to Web App design. My language of expertise is PHP/MySQL. When creating an MVC architecture for an application I'm developing, I always come across the problem of where to store 开发者_如何学Goinvalid form submissions (so that the user doesn't have to re-enter the data, and helpful error messages can be displayed).

Usually I've settled with storing it as a serialized object in a SESSION variable, but my latest reading has told me sessions are bad and take away from stateless web development. A few alternatives I've thought of are:

  1. storing it in the database as I would with valid input, but flagging it as invalid
  2. storing it in the database in a separate table specific for invalid form submissions
  3. storing it in a text file

They all have their downsides.

  1. Not ALL forms result in the creation of a (single) database entity.
  2. and 3. both seem like the same idea as SESSION variables

What would you recommend?


Don't store it at all, just present the user with an error message and another copy of the form. Use the data you have (in $_POST/$_GET since you are working in PHP) to pre-populate the form with the previously entered data.


If the form is publicly available and you do not have user authentification for them, you will lose the visitors when the session ends.

  • So SESSION is the one to consider.
  • If you have users you can save as a Serialized object to database.
  • The other is to use HTML5 local storage which is the best method, but only a few browser support it yet.


1) You can have problems with sessions if you are spreading the application across two or more servers in a round-robin or load balancing scenario but if you have no plans to scale the application larger than one server then this would not apply

2) you could pass the data back and forwards in cookies between the server and the browser. probably using a cookie array to hold the data all together. this way if the user is being round-robined in a load balancing scenario then the data will follow them round and state is irrelevant.


Have a look at zend_form

It handles filling in the data for you. And you can also do automatic validation and filtering of data

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号