Solved

php check form fields for a change of any type

Posted on 2011-09-03
3
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

752 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