Answer the question
In order to leave comments, you need to log in
How to track which form fields have been changed
How can I track which fields have been changed in the form so that later in the PHP script not process the entire form, but only those fields that have been changed or pass only fields with changes to the processing script.
PS: there are quite a lot of fields in the form
Answer the question
In order to leave comments, you need to log in
Write a wrapper that will still compare the received values with the original ones.
You can also try this perverse way:
JS on the client side collects information about the changed fields and then a handler is hung on the submit that sends only the changed fields.
But the essence does not change much ...
There is a fairly simple way, although not very beautiful: when loading the form for editing, all fields are given with name="old_<field name>", and onkeydown old_ is removed from the field name. Those. with the "correct" names, only changed fields go away.
But it’s more correct to send only the changed content, tracking the changes and submitting the form via JS.
Something like this -
<form onSubmit="PreSubmit(this)"> ... </form> <script> function PreSubmit(form) { for (var i = 0; i < form.elements.length; i++) if (form.elements[i].defaultValue == form.elements[i].value) form.elements[i].removeAttribute("name"); } </script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question