如何在jQuery / Ajax弹出窗体中保留用户输入的数据?

时间:2022-07-06 07:46:56

I have a form on a website I'm working (you can see it here) on that allows my users to give feedback. It's an jQuery/Ajax popup form:

我在我正在工作的网站上有一个表单(你可以在这里看到),这样我的用户就可以提供反馈。这是一个jQuery / Ajax弹出窗体:

$('.contact_us').click(function(){
    var boxy_content;
    boxy_content += "<div style=\"width:300px; height:300px \"><form id=\"feedbacked\">";
    boxy_content += "<p>Subject<br /><input type=\"text\" name=\"subject\" id=\"subject\" size=\"33\" /></p><p>Your E-Mail Address:<br /><input type=\"text\" name=\"your_email\" size=\"33\" /></p><p>Comment:<br /><textarea name=\"comment\" id=\"comment\" cols=\"33\" rows=\"5\"></textarea></p><br /><input type=\"submit\" name=\"submit\" value=\"Send >>\" />";
    boxy_content += "</form></div>";

    // Other code here...

Is there anyway I can save what the user has entered in the form after they have clicked the close button and load it there next time the click the feedback button?

无论如何,我可以保存用户在单击关闭按钮后在表单中输入的内容,并在下次单击反馈按钮时将其加载到那里?

2 个解决方案

#1


1  

I would suggest that instead of recreating the whole boxy form on each click of the feedback button, create it once at the beginning and just show/hide it when you want.. this way it will maintain the contents of the previous submission..

我建议不要在每次点击反馈按钮时重新创建整个四四方方的形式,而是在开始时创建一次,只需在需要时显示/隐藏它。这样它将保留先前提交的内容。

Also do not rewrite its contents with the results of the ajax call.. create another box to be used for messages...

也不要用ajax调用的结果重写其内容..创建另一个用于消息的框...

#2


0  

Why not have the form HTML and handling in a separate file, and just load it in using jQuery?

为什么不在单独的文件中使用表单HTML和处理,只需使用jQuery加载它?

It should keep your code cleaner (no messy HTML in JavaScript), and you can easily implement a 'sticky' form by echoing the POST'ed data into the form values server-side.

它应该保持你的代码更清晰(在JavaScript中没有混乱的HTML),你可以通过将POST数据回显到服务器端的表单值来轻松实现“粘性”表单。

UPDATE

UPDATE

Load the form into a dynamic iframe, so that when the user POSTs it, the whole page doesn't refresh.

将表单加载到动态iframe中,以便当用户POST它时,整个页面不会刷新。

#1


1  

I would suggest that instead of recreating the whole boxy form on each click of the feedback button, create it once at the beginning and just show/hide it when you want.. this way it will maintain the contents of the previous submission..

我建议不要在每次点击反馈按钮时重新创建整个四四方方的形式,而是在开始时创建一次,只需在需要时显示/隐藏它。这样它将保留先前提交的内容。

Also do not rewrite its contents with the results of the ajax call.. create another box to be used for messages...

也不要用ajax调用的结果重写其内容..创建另一个用于消息的框...

#2


0  

Why not have the form HTML and handling in a separate file, and just load it in using jQuery?

为什么不在单独的文件中使用表单HTML和处理,只需使用jQuery加载它?

It should keep your code cleaner (no messy HTML in JavaScript), and you can easily implement a 'sticky' form by echoing the POST'ed data into the form values server-side.

它应该保持你的代码更清晰(在JavaScript中没有混乱的HTML),你可以通过将POST数据回显到服务器端的表单值来轻松实现“粘性”表单。

UPDATE

UPDATE

Load the form into a dynamic iframe, so that when the user POSTs it, the whole page doesn't refresh.

将表单加载到动态iframe中,以便当用户POST它时,整个页面不会刷新。