-> How to read a form variable before posting? <-

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

    -> How to read a form variable before posting? <-

    Hi,
    is there a way to read the content of a form variable before
    a POST?

    I have a form with a "duplicate" button which opens a new form
    with most of the fields filled with the values of the calling one.
    To do so, I pass the id of the form to be duplicated.
    Example:
    - I have a form with "Number = 1234567" in a "numform" edit field.
    - Duplicate has a href=/duplicateform.p hp?id=1234567
    - then the "duplicateform. php" reads id with a GET['id']

    This is easy as I come from a displayed form that retrieves its
    values via a SQL statement and with a specific "number" reference.

    Now, once I am in this new form, I have a save button to save all
    values, including the new "Number" the user would type in, say
    "22222222". The save process works correctly via AJAX and saves the
    record using a POST action.
    But then, I still have my "duplicate" button which should now
    point to href=/duplicateform.p hp?id=22222222
    How can I get this 22222222 value from within the form itself?
    I have to get it from the "numform" field, but how can I do this?

    it would be something like
    href=/duplicateform.p hp?id=<?=[value_of_field_ number]?>

    with value_of_field_ number being the actual value of that edit field.

    Any help would be appreciated.



    Sincerely,
    Steve JORDI

    (Remove the K_I_L_LSPAM from my email address)
    ------------------------------------------------
    1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
    Switzerland WWW: www.sjordi.com
    ------------------------------------------------
    Volcanoes at www.sjordi.com/volcanoes
    MovieDB at www.sjmoviedb.com
    ------------------------------------------------
  • Steve JORDI

    #2
    Re: -&gt; How to read a form variable before posting? &lt;-

    As a complement to my question...

    I have a hidden form field called "recid" with id="recid".

    By default it's set to "-1" to let me know the form is new
    and has not been stored in the database.

    I was thinking about adding a javascript event to the field's
    onBlur() event like:
    getElementById( "recid").va lue = getElementById( "number").v alue

    to store the value currently in my field.

    Then I could use a reference like

    <A href="/formduplicate.p hp?id=<?=$_GET['recid']?>">...</a>

    But I'm afraid that this would not work as the recid variable was not
    part of a POST event or passed as an URL argument.

    Is this correct?


    Sincerely,
    Steve JORDI

    (Remove the K_I_L_LSPAM from my email address)
    ------------------------------------------------
    1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
    Switzerland WWW: www.sjordi.com
    ------------------------------------------------
    Volcanoes at www.sjordi.com/volcanoes
    MovieDB at www.sjmoviedb.com
    ------------------------------------------------

    Comment

    • Floortje

      #3
      Re: -&gt; How to read a form variable before posting? &lt;-

      How can I get this 22222222 value from within the form itself?
      I have to get it from the "numform" field, but how can I do this?
      Hi, check out mysql_insert_id ()

      --
      Arjen
      http://www.hondenpage.com - mijn site over honden

      Comment

      • Steve JORDI

        #4
        Re: -&gt; How to read a form variable before posting? &lt;-

        Actually, the following code sample works ok to built
        the href tag dynamically...

        <script language="javas cript" type="text/javascript">
        function toto() {
        var num = document.getEle mentById("num") ;
        var ref=document.ge tElementById("t heref") ;
        ref.href="mypag e.php?id="+num. value ;
        }
        </script>

        <form method="post">
        <INPUT name="num" type="text" id="num" onBlur="toto(); ">
        <A href="" id="theref">go </a>
        </form>

        When I click on "go" the link is correct and point to mypage
        with the id= to the value I have in the edit field.

        This allows me to know where to point to before POSTING. That's
        what I need.


        Sincerely,
        Steve JORDI

        (Remove the K_I_L_LSPAM from my email address)
        ------------------------------------------------
        1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
        Switzerland WWW: www.sjordi.com
        ------------------------------------------------
        Volcanoes at www.sjordi.com/volcanoes
        MovieDB at www.sjmoviedb.com
        ------------------------------------------------

        Comment

        • shimmyshack

          #5
          Re: -&gt; How to read a form variable before posting? &lt;-

          On May 14, 2:56 pm, Steve JORDI <steveK_I_L_LSP AMjo...@hotmail .com>
          wrote:
          Actually, the following code sample works ok to built
          the href tag dynamically...
          >
          <script language="javas cript" type="text/javascript">
          function toto() {
          var num = document.getEle mentById("num") ;
          var ref=document.ge tElementById("t heref") ;
          ref.href="mypag e.php?id="+num. value ;
          }
          </script>
          >
          <form method="post">
          <INPUT name="num" type="text" id="num" onBlur="toto(); ">
          <A href="" id="theref">go </a>
          </form>
          >
          When I click on "go" the link is correct and point to mypage
          with the id= to the value I have in the edit field.
          >
          This allows me to know where to point to before POSTING. That's
          what I need.
          >
          Sincerely,
          Steve JORDI
          >
          (Remove the K_I_L_LSPAM from my email address)
          ------------------------------------------------
          1197 Prangins Email: stevejordiK_I_L _LS...@hotmail. com
          Switzerland WWW: www.sjordi.com
          ------------------------------------------------
          Volcanoes at www.sjordi.com/volcanoes
          MovieDB at www.sjmoviedb.com
          ------------------------------------------------
          of course you could just post to mypage, and use
          $_GET['id'] = $_POST['numform']; //with filtering of course!
          if you REALLY need to populate the GET array.

          Comment

          • Steve JORDI

            #6
            Re: -&gt; How to read a form variable before posting? &lt;-

            I actually need to know the id of my record BEFORE
            posting, so I can dynamically create the <A href>
            link with the correct value passed to the mypage file.

            So my javascript function does exactly what I need.

            Thanks anyway.

            Sincerely,
            Steve JORDI

            (Remove the K_I_L_LSPAM from my email address)
            ------------------------------------------------
            1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
            Switzerland WWW: www.sjordi.com
            ------------------------------------------------
            Volcanoes at www.sjordi.com/volcanoes
            MovieDB at www.sjmoviedb.com
            ------------------------------------------------

            Comment

            • shimmyshack

              #7
              Re: -&gt; How to read a form variable before posting? &lt;-

              On May 14, 3:10 pm, Steve JORDI <steveK_I_L_LSP AMjo...@hotmail .com>
              wrote:
              I actually need to know the id of my record BEFORE
              posting, so I can dynamically create the <A href>
              link with the correct value passed to the mypage file.
              >
              So my javascript function does exactly what I need.
              >
              Thanks anyway.
              >
              Sincerely,
              Steve JORDI
              >
              (Remove the K_I_L_LSPAM from my email address)
              ------------------------------------------------
              1197 Prangins Email: stevejordiK_I_L _LS...@hotmail. com
              Switzerland WWW: www.sjordi.com
              ------------------------------------------------
              Volcanoes at www.sjordi.com/volcanoes
              MovieDB at www.sjmoviedb.com
              ------------------------------------------------
              if you say so

              Comment

              Working...