468,119 Members | 1,863 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

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']."?".$_SERVER['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>
Apr 19 '06 #1
4 1259
mickey wrote:
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.
You could use hidden fields to pass the data


<form name="form1" method="post" action="<?php echo
$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>">
<table>
<tr>
<th><input type="text" name="fields[]"</th>
...
<th><input type="text" name="fields[]"</th>
<?php
foreach($_POST as $k => $v)
echo '<input type="hidden" name="' . $k . '" value="' .
stripslashes($v) . '">';
?>
<th><input type="submit" value="Add" name="add"</th>
</tr>
</table>
</form>


Ken

Apr 19 '06 #2
"mickey" <mi**************************@ignore.this> wrote in message
news:cB*******************@bignews5.bellsouth.net. ..


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']."?".$_SERVER['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>

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.
Apr 19 '06 #3

Works beautifully, thank you!

Ken Robinson wrote:
mickey wrote:
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.


You could use hidden fields to pass the data

<form name="form1" method="post" action="<?php echo
$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>">
<table>
<tr>
<th><input type="text" name="fields[]"</th>
...
<th><input type="text" name="fields[]"</th>


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


Ken

Apr 19 '06 #4
I tried the hidden approach and it worked, thank you.

Bruno wrote:
"mickey" <mi**************************@ignore.this> wrote in message
news:cB*******************@bignews5.bellsouth.net. ..

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']."?".$_SERVER['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>

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.

Apr 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by qsweetbee | last post: by
9 posts views Thread by Dom Boyce | last post: by
20 posts views Thread by Jack Schitt | last post: by
8 posts views Thread by newbie | last post: by
2 posts views Thread by Chris Millar | last post: by
47 posts views Thread by Jo | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.