I’m working with a friend – helping him with some dynamic coding – on a web site. The web site was put together by a different webmaster and it functions. The clients needs have changed over time, and changes are need to the site to comply with a few legal things (it deals with housing.) As I begin looking at the PHP code, I can tell the person who programmed it was very intelligent, but fell prey to some of the things that irritate me, and create problems when trying to update the code as I’m doing now.
First, they didn’t comment any of their PHP code, second they did make use of arrays, but did a poor job of it, and they posted all of the forms back to themselves, which brings me to the point of this post. Use more than one file if you have to, and don’t be afraid to do so. Here’s the problem with posting a form back to itself.
In this case we have a form that is sending the accumulated form data via email to the client for review. That data is also saved to a database so that it can be edited and tracked in the event that the user becomes a tenant. The problem is that since the form post to itself, the client receives and email, and the database gets a new row added every time the page is refreshed after the user fills it out.
When I saw this I recommended to my friend that over time we fix this. It turns out that there are revisions that need to be made to the form anyway, so as we fix the form, we’ll setup additional pages to process the form data, and redirect to the next part of the form ( there are 3 parts to the form.) This way when the user clicks the final submit button, the information will be emailed, collected in to the database and then the user will be taken to a thank you page. This process will keep the redundant & superfluous rows out of the clients inbox and database.
In this example, just by processing the form data with another, you reduce the irritation to the client and to yourself because they won’t keep asking… “Why do I get two or three emails for some people, and why do they show up that many times in the database?”