Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

php check form fields for a change of any type

I have a project nearing completion that allows members of an organizatin to login and review their membership records, make changes and submit them to a mysql database for update. I have several fields that might be modified by the user and a few that are read only and wont be modified. I am using SESSION and POST to pass variable from page to page and all of that is working well. I am coding the mysql update function now and I want to detect the submitted form fields for a change from the initial value (i.e the user modified their info in a field) and then based on knowing which fields had a change I will run the correct update query for those specific updates and avoid running an update query on fields that had no change. Again I know the value of all of the variables coming from the form fields so I am not needing help on that just need to know Is there a change or not.  I know there are a couple of javascript event handlers that can be used but I want to avoid javascript in this particular project (I already have some JS but want to avoid it here). I am looking at compairng the intial values for each field as they are specific to the user that is logged in and were extracted from the database and placed in varaibles that were displayed in forms. After review,  the user will either make  changes and submit, log out or even submit with no changes. I need to know if  change(s) or no change was made to each form field. Again I want to do this in php if possible. Im looking for a tight method that I can apply to get the information as described. I'm in a bit of a hurry as always so anyone with ideas or solutions please throw them this way.
0
Ron McCain
Asked:
Ron McCain
2 Solutions
 
ghodderCommented:
The way I normally do it is store the current values in a cookie or session after I pull them from the database, then after they submit the form I check the values submitted against what was previously stored and if there are changes I update the database. I like using cookies/session because they're easily encrypted in 1 hit if there are password fields involved. You could also just generate hidden form fields with the current values if you wanted to avoid cookies.

If one of the fields is a password don't output the password in plain text as anyone who viewed the page source would obviously be able to see it. Either store a hash in the hidden field or just assume that if they have typed a new password into your 2 password fields and both password fields are equal they must want to change their password from whatever they currently use.
0
 
Ray PaseurCommented:
One design pattern that I have used successfully goes something like this:

Put the client identifier into the URL GET argument string, or store it in a cookie.  You can then give the client a link that says "Update my information."  

Use the client identifier to look up the client record and use the client record to pre-populate the HTML form.

When the client submits the form. write the submitted form information into the data base.  You do not need to detect what changed - just store the information that the client presented (subject to your own business rules, of course) and then present the form again.  Once your client is satisfied, she will navigate away.  Many high-level web sites do this, including Twitter, Facebook, etc.
0
 
Ron McCainAuthor Commented:
I settled on using seesion array to test initial values from database against POST values, seems to work well. I got great info from both experts so I split the accepted solution points between them. Thanks for the fast response folks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now