jaxdevil Posted October 17, 2008 Share Posted October 17, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/ Share on other sites More sharing options...
Maq Posted October 17, 2008 Share Posted October 17, 2008 Why don't you submit it to the same page and do the changes there? Anyway, this may help, you can loop through $_POSTS. foreach ($_POST as $key => $value) { ?> } Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668109 Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 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() Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668110 Share on other sites More sharing options...
discomatt Posted October 17, 2008 Share Posted October 17, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668111 Share on other sites More sharing options...
Maq Posted October 17, 2008 Share Posted October 17, 2008 update: Maq posted something similar, but i'm still posting mine, cus you should wrap the values in htmlspecialchars() Good call. Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668115 Share on other sites More sharing options...
jaxdevil Posted October 17, 2008 Author Share Posted October 17, 2008 That works! Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668129 Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 the only thing i ask, is to please make your site still work if i hit the back button Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668130 Share on other sites More sharing options...
Maq Posted October 17, 2008 Share Posted October 17, 2008 the only thing i ask, is to please make your site still work if i hit the back button It still works but goes to the home page. Quote Link to comment https://forums.phpfreaks.com/topic/128869-solved-automatically-generate-hidden-form-fields-from-post-array/#findComment-668142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.