开发者

Preserving data in one form when submitting a second form

I have a page with two forms that is generated with PHP.

The first part contains text boxes, a submit button and a clear button.

The second form is just a button called "Add more text boxes" so the user can add more to his form if he needs to.

The problem is when I click the "Add more rows" which loads another 开发者_如何转开发page which changes a value.

This value then affects the original page when it reloads causing more text boxes to get created.

The problem is that I lose all the data that was entered.

Is there any way to preserve the data when the user clicks "Add more rows"?.

Here's a screenshot of my page.

Preserving data in one form when submitting a second form

Thanks


If you want to do it without js than you put all in one form. When you click button to add row all entered data will be available in $_POST or $_GET so you can fill form with existing data and add a row when generating new page.


Ideally you should use javascript to dynamically add new rows w/out making new requests to the server and loading new pages. But if you want to keep it javascript free. If it's all the same php script just controlled by conditions, just use the $_POST['variable'] values as the value="$_POST['variable']" in your fields. If it's handled through multiple scripts, you can use a session variable to pass the data from one page to the next.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜