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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rider

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

    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
  • Erwin Moller

    #2
    Re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????

    Rider schreef:
    Hi All,
    Here is the reason why i ak asking for ur help.
    Hi,
    >
    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?

    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 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["formnamehe re"].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.javas cript

    Good luck.

    Regards,
    Erwin Moller
    >
    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

    Comment

    • Sven Reuter

      #3
      Re: How do I get form elements values BEFORE SUBMIT & AFTERSUBMIT????

      Rider wrote:
      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 ($valuesFromFor m as $key =$value) {
      if ($value != $valuesFromDB[$key]) {
      // value with key $key changed
      }
      }


      Sven Reuter
      --


      Comment

      • Jerry Stuckle

        #4
        Re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????

        Rider wrote:
        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@attgl obal.net
        =============== ===

        Comment

        • sheldonlg

          #5
          Re: How do I get form elements values BEFORE SUBMIT & AFTER SUBMIT????

          Erwin Moller wrote:
          Rider schreef:
          >Hi All,
          >Here is the reason why i ak asking for ur help.
          >
          Hi,
          >
          >>
          >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?
          >
          >
          >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.

          Comment

          • Gordon Burditt

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

            Comment

            Working...