Solved

php check form fields for a change of any type

Posted on 2011-09-03
3
291 Views
Last Modified: 2012-06-27
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
Comment
Question by:Ron McCain
3 Comments
 
LVL 9

Accepted Solution

by:
ghodder earned 250 total points
ID: 36479620
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 36481325
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
 

Author Closing Comment

by:Ron McCain
ID: 36483188
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now