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

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.