通过在新页面上基于上一页创建隐藏的表单元素来保留表单元素

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过在新页面上基于上一页创建隐藏的表单元素来保留表单元素相关的知识,希望对你有一定的参考价值。

I made this function to render hidden form elements in a new page based on what was sent from the last form. This function can be used to preserve input from a long multiple-page form.

What does it do:

1. Go through all the submitted POST elements.
2. Draw a loop of those POST elements into this new form (in form of hidden elements).
3. When that form submits, previous page's input is included inside this new form's submit action.

Note: Do not use the same form element name as it overwrites as it goes along.
  1. function retain_post_data() {
  2. foreach($_POST as $key=>$index) {
  3. if (is_array($index) == false) {
  4. $index = trim($index);
  5. $form .= "<input name='$key' type='hidden' value='".$index."' />";
  6.  
  7. }
  8. else {
  9. foreach($index as $key2=>$index2) {
  10. if ($index2 != "") $form .= "<input name='".$key."[".$key2."]' type='hidden' value='$index2' />";
  11. }
  12. }
  13. }
  14.  
  15. return $form;}

以上是关于通过在新页面上基于上一页创建隐藏的表单元素来保留表单元素的主要内容,如果未能解决你的问题,请参考以下文章

单击“转到上一页”链接返回上一个窗口[重复]

js返回上一页效果

在不丢失原始数据的情况下重定向回上一页

Web页面向后台提交数据的方式和选择

使用jQuery ui创建模态表单

弹出确认框[重复]