简体   繁体   English

提交表单后从另一个页面(如确认页面)重定向后,如何将值保留在表单中

[英]How to keep the values in a form after getting redirected from another page(like a confirmation page) after submitting the form

This question is not about traditionally keeping the values in form after form submission. 这个问题不是关于表单提交后传统上保持表单值的问题。 I am creating an E-learning portal where I have to create a functionality where I need to make questions for test papers. 我正在创建一个电子学习门户,我必须在其中创建需要提出试卷问题的功能。 I have created a form as shown in the picture here:- 我创建了一个表格,如图所示:- 链接到我的表格

Now when I submit the form after filling all the values , it is going to redirect me to a confirmation page saying "Do you want to enter another question".If I click on yes it should redirect me to the same page to create the question as shown in picture I have attached but this time the form should have already entered values which I entered before submitting the earlier question. 现在,当我填写完所有值后提交表单时,它将重定向我到确认页面,提示您“是否要输入另一个问题”。如果单击“是”,它将重定向我到同一页面以创建问题如我所附的图片所示,但是这次表单应该已经输入了在提交之前的问题之前输入的值。 For example, Take a paragraph comprehension question.You don't need to enter the paragraph again and again, you just have to enter the question you need to ask on that comprehension.Consider this as the base of my program. 例如,以一个段落理解问题为例,您不需要一遍又一遍地输入段落,只需输入要对该理解理解的问题,就可以将此作为我程序的基础。

Please help me and guide me how to create such functionality. 请帮助我,并指导我如何创建此类功能。 Thanks in advance. 提前致谢。

You can use localStorage from javascript to keep and set your data. 您可以使用javascript中的localStorage来保存和设置数据。

// To get
if(localStorage.getItem('your-datas')){
    var datas = JSON.parse(localStorage.getItem('your-datas'));  
}
// To set
var myData = {section: $("#section").val(),...};
localStorage.setItem('your-datas', JSON.stringify(myData));

Here the link with a basic usage: https://www.w3schools.com/html/html5_webstorage.asp 这里是基本用法的链接: https : //www.w3schools.com/html/html5_webstorage.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM