Solved

php check form fields for a change of any type

Posted on 2011-09-03
3
295 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 109

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

813 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