开发者

Detecting if the form field values have been modified

开发者 https://www.devze.com 2023-01-12 16:24 出处:网络
I have a multi-step form which asks the subscriber to check their details before proceeding with the renewal process.

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 开发者_C百科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?


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.


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消