Jump to content

[SOLVED] Automatically generate hidden form fields from post array


jaxdevil

Recommended Posts

I have a form that posts to a page, that page does a function that retrieves some new data, then it posts itselfs back to the original page with the new data and the old data. I am trying to figure out how to automatically generate one hidden form input for each item that is posted from the original page, so that when I post to the function page, it recreates all of the posts as hidden form fields, so when it resubmits back to the original page it will send the new data as well as the old data back. Thats is of course without me writing each hidden input line manually. Any ideas?

 

Thanks,

SK

Rather then doing all that, I would recommend storing the info in the SESSION.

 

but to answer your question:

<?php
  foreach($_POST as $key=>$value)
    printf('<input type="text" name="%s" value="%s" />',htmlspecialchars($key),htmlspecialchars($value));
?>

 

update: Maq posted something similar, but i'm still posting mine, cus you should wrap the values in htmlspecialchars()

Sessions will add a slight overhead in processing, but will save a little bit of bandwidth. doesn't it seem kind of redundant for the user to submit data, only to have the server send it back on the next page, forcing the user to send the data to the server a second time?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.