Help with posting form fields

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

    Help with posting form fields



    I have a form like the one below. Upon submit I would like to self post
    to the same page but have the original $_POST data( which was posted to
    this page from another ) also be sent along with the new form field
    data. How can I achieve that? Thanks.


    <form name="form1" method="post" action="<?php echo
    $_SERVER['PHP_SELF']."?".$_SERVE R['QUERY_STRING']; ?>">
    <table>
    <tr>
    <th><input type="text" name="fields[]"</th>
    ....
    <th><input type="text" name="fields[]"</th>
    <th><input type="submit" value="Add" name="add"</th>
    </tr>
    </table>
    </form>
  • Ken Robinson

    #2
    Re: Help with posting form fields

    mickey wrote:[color=blue]
    > I have a form like the one below. Upon submit I would like to self post
    > to the same page but have the original $_POST data( which was posted to
    > this page from another ) also be sent along with the new form field
    > data. How can I achieve that? Thanks.[/color]

    You could use hidden fields to pass the data
    [color=blue]
    >
    >
    > <form name="form1" method="post" action="<?php echo
    > $_SERVER['PHP_SELF']."?".$_SERVE R['QUERY_STRING']; ?>">
    > <table>
    > <tr>
    > <th><input type="text" name="fields[]"</th>
    > ...
    > <th><input type="text" name="fields[]"</th>[/color]

    <?php
    foreach($_POST as $k => $v)
    echo '<input type="hidden" name="' . $k . '" value="' .
    stripslashes($v ) . '">';
    ?>
    [color=blue]
    > <th><input type="submit" value="Add" name="add"</th>
    > </tr>
    > </table>
    > </form>[/color]

    Ken

    Comment

    • Bruno

      #3
      Re: Help with posting form fields

      "mickey" <miguelportilla ATpobrosDOTcom@ ignore.this> wrote in message
      news:cBt1g.3197 9$Jk3.14040@big news5.bellsouth .net...[color=blue]
      >
      >
      > I have a form like the one below. Upon submit I would like to self post to
      > the same page but have the original $_POST data( which was posted to this
      > page from another ) also be sent along with the new form field data. How
      > can I achieve that? Thanks.
      >
      >
      > <form name="form1" method="post" action="<?php echo
      > $_SERVER['PHP_SELF']."?".$_SERVE R['QUERY_STRING']; ?>"> <table> <tr>
      > <th><input type="text" name="fields[]"</th>
      > ...
      > <th><input type="text" name="fields[]"</th>
      > <th><input type="submit" value="Add" name="add"</th>
      > </tr>
      > </table> </form>[/color]


      You could save the values in a cookie, and retrieve them on the next page
      load (see the setcookie function).

      Alternatively, you could add them to the next form as hidden fields, so they
      are passed along with the current values on the next form post.


      Comment

      • mickey

        #4
        Re: Help with posting form fields


        Works beautifully, thank you!

        Ken Robinson wrote:[color=blue]
        > mickey wrote:[color=green]
        >> I have a form like the one below. Upon submit I would like to self post
        >> to the same page but have the original $_POST data( which was posted to
        >> this page from another ) also be sent along with the new form field
        >> data. How can I achieve that? Thanks.[/color]
        >
        > You could use hidden fields to pass the data
        >[color=green]
        >>
        >> <form name="form1" method="post" action="<?php echo
        >> $_SERVER['PHP_SELF']."?".$_SERVE R['QUERY_STRING']; ?>">
        >> <table>
        >> <tr>
        >> <th><input type="text" name="fields[]"</th>
        >> ...
        >> <th><input type="text" name="fields[]"</th>[/color]
        >
        > <?php
        > foreach($_POST as $k => $v)
        > echo '<input type="hidden" name="' . $k . '" value="' .
        > stripslashes($v ) . '">';
        > ?>
        >[color=green]
        >> <th><input type="submit" value="Add" name="add"</th>
        >> </tr>
        >> </table>
        >> </form>[/color]
        >
        > Ken
        >[/color]

        Comment

        • mickey

          #5
          Re: Help with posting form fields

          I tried the hidden approach and it worked, thank you.

          Bruno wrote:[color=blue]
          > "mickey" <miguelportilla ATpobrosDOTcom@ ignore.this> wrote in message
          > news:cBt1g.3197 9$Jk3.14040@big news5.bellsouth .net...[color=green]
          >>
          >> I have a form like the one below. Upon submit I would like to self post to
          >> the same page but have the original $_POST data( which was posted to this
          >> page from another ) also be sent along with the new form field data. How
          >> can I achieve that? Thanks.
          >>
          >>
          >> <form name="form1" method="post" action="<?php echo
          >> $_SERVER['PHP_SELF']."?".$_SERVE R['QUERY_STRING']; ?>"> <table> <tr>
          >> <th><input type="text" name="fields[]"</th>
          >> ...
          >> <th><input type="text" name="fields[]"</th>
          >> <th><input type="submit" value="Add" name="add"</th>
          >> </tr>
          >> </table> </form>[/color]
          >
          >
          > You could save the values in a cookie, and retrieve them on the next page
          > load (see the setcookie function).
          >
          > Alternatively, you could add them to the next form as hidden fields, so they
          > are passed along with the current values on the next form post.
          >
          >[/color]

          Comment

          Working...