A
A
Alexander2010-10-13 14:23:12
PHP
Alexander, 2010-10-13 14:23:12

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

4 answer(s)
D
DevMan, 2010-10-13
@zlobin

For example, use api.jquery.com/change/ and submit what you need.

C
Chvanikoff, 2010-10-13
@Chvanikoff

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 ...

L
lafayette, 2010-10-13
@lafayette

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.

H
Hotpilot, 2010-10-13
@Hotpilot

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 question

Ask a Question

731 491 924 answers to any question