Connecting Tech Pros Worldwide Help | Site Map

How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????

  #1  
Old November 18th, 2008, 08:15 AM
Rider
Guest
 
Posts: n/a
Hi All,
Here is the reason why i ak asking for ur help.

I have a edit form in which the values already stored in DB are
populated.
User can edit some or all the values in the form.
then he submit the form.

NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
submitting & after submitting.
I HAVE TO COMPARE these values so that i can send only changed values
to server.

I HAD TRIED form.elements in JAVASCRIPT BUT IT GIVES SAME VALUES.

Regards,
Rider
  #2  
Old November 18th, 2008, 08:45 AM
Erwin Moller
Guest
 
Posts: n/a

re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????


Rider schreef:
Quote:
Hi All,
Here is the reason why i ak asking for ur help.
Hi,
Quote:
>
I have a edit form in which the values already stored in DB are
populated.
User can edit some or all the values in the form.
then he submit the form.
>
NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
submitting & after submitting.
Which should be WHAT?

Quote:
I HAVE TO COMPARE these values so that i can send only changed values
to server.
>
If you want to do that before submitting, you need a JavaScript solution.
And why don't you take the whole form, and update all posted? Why do you
want to 'flag' the elements that are changed?

Quote:
I HAD TRIED form.elements in JAVASCRIPT BUT IT GIVES SAME VALUES.
???
Form.elements is not valid since you didn't name the form which you are
addressing.

You need to start with:
document.forms["formnamehere"].elements etc.

But this has nothing to do with PHP.
You must learn how: HTML and forms work and how different formelements
(eg text, radio, checkbox, select, etc) are addressed from JavaScript.

For JavaScript questions you better post here: comp.lang.javascript

Good luck.

Regards,
Erwin Moller
Quote:
>
Regards,
Rider

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
  #3  
Old November 18th, 2008, 08:45 AM
Sven Reuter
Guest
 
Posts: n/a

re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????


Rider wrote:
Quote:
I have a edit form in which the values already stored in DB are
populated.
User can edit some or all the values in the form.
then he submit the form.
>
NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
submitting & after submitting.
I HAVE TO COMPARE these values so that i can send only changed values
to server.
>
I HAD TRIED form.elements in JAVASCRIPT BUT IT GIVES SAME VALUES.
>
First of all: Your problem is not more important only because you use more
than one question mark or write in capital letters.

$valuesFromDB = ...;
$valuesFromForm = $_POST;

foreach ($valuesFromForm as $key =$value) {
if ($value != $valuesFromDB[$key]) {
// value with key $key changed
}
}


Sven Reuter
--
http://www.sReuter.net/
http://www.Auskennbert.de/
  #4  
Old November 18th, 2008, 12:45 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????


Rider wrote:
Quote:
Hi All,
Here is the reason why i ak asking for ur help.
>
I have a edit form in which the values already stored in DB are
populated.
User can edit some or all the values in the form.
then he submit the form.
>
NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
submitting & after submitting.
I HAVE TO COMPARE these values so that i can send only changed values
to server.
>
I HAD TRIED form.elements in JAVASCRIPT BUT IT GIVES SAME VALUES.
>
Regards,
Rider
Calm down. You don't have to yell to get help here.

If your data is stored in the db, then you should fetch the data from
the db again, and compare each item with its respective item in the form.

This should be done on the server end, not the client, which means all
data in the form goes to the server. Anything else would be unreliable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #5  
Old November 18th, 2008, 05:25 PM
sheldonlg
Guest
 
Posts: n/a

re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????


Erwin Moller wrote:
Quote:
Rider schreef:
Quote:
>Hi All,
>Here is the reason why i ak asking for ur help.
>
Hi,
>
Quote:
>>
>I have a edit form in which the values already stored in DB are
>populated.
>User can edit some or all the values in the form.
>then he submit the form.
>>
>NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
>types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
>submitting & after submitting.
>
Which should be WHAT?
>
>
Quote:
>I HAVE TO COMPARE these values so that i can send only changed values
>to server.
>>
>
If you want to do that before submitting, you need a JavaScript solution.
And why don't you take the whole form, and update all posted? Why do you
want to 'flag' the elements that are changed?
I have to agree wholeheartedly here. In fact, I was going to post the
same comment. Only putting up the flagged stuff leads to complex
coding. Just stick the whole thing in with one update. MUUUUCCCCHHHHH
easier -- AND less error prone.
  #6  
Old November 18th, 2008, 08:15 PM
Gordon Burditt
Guest
 
Posts: n/a

re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????


>I have a edit form in which the values already stored in DB are
Quote:
Quote:
>populated.
>User can edit some or all the values in the form.
>then he submit the form.
>>
>NOW I WANT SOME JAVASCRIPT / PHP FUNCTIONALITY WHICH WILL GIVE ME THE
>types & values OF ALL ELEMENTS ON FORM WHICH SHOULD BE before
>submitting & after submitting.
It is not uncommon to use hidden fields to contain the original values
of something so those values can be checked when the form is submitted.
This requires some manual effort. Yes, the original values can be
tampered with by the user, but since this user is authorized to edit
records anyway, there isn't much point.
Quote:
Quote:
>I HAVE TO COMPARE these values so that i can send only changed values
>to server.
>>
>I HAD TRIED form.elements in JAVASCRIPT BUT IT GIVES SAME VALUES.
>>
>Regards,
>Rider
>
>Calm down. You don't have to yell to get help here.
>
>If your data is stored in the db, then you should fetch the data from
>the db again, and compare each item with its respective item in the form.
It is not uncommon to use the original values to check for multiple
editing of the same record by different people, especially in an
environment where people go to lunch or on extended vacations while
leaving the edit page open. This is used as a less-annoying
substitute for locking, which is impractical in a web-based environment
anyway.

You compare the original values on the page with the data from the
database. If they don't match, someone else has been editing the
page. You can tell what changes were made by this edit (original
form data vs. new form data) and what changes were made by the other
edit (original form data vs. database data). If you decide the
changes were conflicting, you can reject the change and ask the
user to do it again, showing them fresh original data. This also
works against the same user submitting the same change form twice.

Two separate changes to the 'salary' field are probably conflicting.
(One HR person was given instructions for a 5% raise for the
department; the other a 1% bonus for this employee. Two simultaneous
edits probably wipe out one or the other raise). A change to the
cell phone number and a change to the 'salary' field probably aren't.
Quote:
>This should be done on the server end, not the client, which means all
>data in the form goes to the server. Anything else would be unreliable.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript not working on my PC but ok on others drwyness answers 16 August 22nd, 2008 12:04 AM
Can't make this page work scottyman@comcast.net answers 6 March 9th, 2006 04:25 AM