views:

30

answers:

2

I have a multi-step form which asks the subscriber to check their details before proceeding with the renewal process.

What I want to do is check if the form has been modified from its pre-filled values (extracted from a Web Service) and then write it to my own local MySQL database. This should only happen if the values have been modified from the original.

I know I can do this by using the == operator but I was wondering if there was a more efficient way to do this?

+1  A: 

You can do it with (multidimensional) arrays. Name the form/service variables carefully then compare them upon submit with array_diff which tells you which values has been modified. Because you said this is a multi-step form, of course you can collect previously submitted values in a $_SESSION variable too.

fabrik
A: 

You could do this with javascript on client side:

HTML

<input type="text" id="username">

Javascript

var input = $('#username');
if (input.defaultValue != input.value) {
    //Do stuff if different 
} else {
    //Do stuff if equal
}
Rui Carneiro
This can be tricked (if the client has disabled JS) or would be heavy if the form is big or (as the OP stated) the form is multi-step.
fabrik