可编辑的表格并保存更改 [英] Editable Form and save changes

查看:128
本文介绍了可编辑的表格并保存更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这似乎并不困难。

我想创建一个带有几个文本框的HTML表单,这个文本框允许用户输入一些数据,并且我希望将这些更改保存到表单中。

例如,如果我的html页面显示:


名称:[] p>

...我希望某人能够点击 [] 并且输入他们的名字等,然后点击SAVE
,然后用表单说: b
$ b


名称:人员姓名


如果有人想更新它,他们可以点击该人的姓名并更改它,然后单击保存并自行更新HTML表单。



我该怎么做?我到处都在寻找,人们都在谈论HTML5和PHP。是否真的很复杂,使这样一个简单的页面?

(如果我不清楚我的HTML我使用 contenteditable =true选项。我如何保存这些更改?) 问题表明您还不知道网页(包括表单)是无状态的,这意味着它们不会自动保存或存储您对它们执行的任何操作。很抱歉,令人失望,但作为初学者,您将很难找到一个简单的解决方案。



这并不是说它不能完成 - 你没有怀疑无处不在 - 但你的知识水平会忽略这样一个事实,即你需要实际编程逻辑来确定你的表格将如何出现以存储信息并在稍后的访问中复制它。



以下是一个简短的摘要:

当用户使用表单时,已经发生了一些事情以查看表单:


  1. 用户请求了该页面(输入网址或点击链接)


  2. 网络服务器已发送请求的网页(即您的网站已发送表单)


  3. $ b

    接下来发生的事情是用户在表单上输入一些数据。这些数据并没有存储在任何地方 - 如果刷新页面数据不见了,因为步骤1和2再次发生。

    因此,要避免这种情况,您可以使用多个工具:


    Javascript :这可以在用户的​​计算机上运行。您可以使用它来查明某个表单上是否存在某些内容,并将其存储在例如cookie中。



    然后,您将必须构建一些逻辑进入你的页面,说:如果我的用户刷新页面或稍后返回到本网站,则查找cookie。如果它存在,那么在用户到达之前将其取值并预先填写表单



    服务器端脚本:这个逻辑可以嵌入到您的web服务器中(使用像PHP这样的服务器端脚本)实际上在步骤2中运行。

    或者,您可以将其构建到JavaScript功能中,当用户实际接收到页面时触发该功能。这将是第3步。

    第二个替代方案将这两个想法(在用户端进行处理并在Web服务器端进行处理)结合在一起,称为AJAX,这基本上意味着您的javascript和PHP之间的讨论会在数据输入或更改时即时发生。



    最后,您可能要考虑PHP会话来存储数据,和/或mySQL数据库。最近,随着现代浏览器的出现,您现在可以将信息存储在用户浏览器可用的本地数据库中。



    在所有这些情况下,您将需要了解这些组件如何相互交流,如何检索信息,以及如何更新无状态和静态表单。



    它不像你想象的那么简单...


    I'm hoping this isn't harder than it seems.

    I want to create an HTML form with a few text boxes that will allow people to enter in some data and I want these changes to be saved to the form.

    For example, if my html page says:

    Name: [ ]

    ...I want someone to be able to click on the [] and enter their name, etc. and click SAVE and then have the form say:

    Name: "Name of Person"

    If someone wants to update that, they can click on the person's name and change it and click SAVE and have the HTML form update itself.

    How can I do this? I've looked everywhere and people are talking about HTML5 AND PHP. Is it really that complicated to make a simple page like this?

    (In case I wasn't clear in my html I'm using the contenteditable="true" option. How can I save those changes?)

    解决方案

    I think your question indicates that you don't already know that web pages (including forms) are "stateless", meaning that they do not "automatically" hold or store anything that you do with them. Sorry to disappoint, but as a beginner you will struggle to find "an easy" solution to this.

    That is not to say it can't be done - you no doubt see it everywhere - but your level of knowledge misses the fact that you need to actually program the logic to determine how your form will "appear" to store the information and reproduce it on a later visit.

    Here's a (really) brief summary:

    When your form is used by your user, a couple of things have already taken place before they get to see the form:

    1. the user has requested the page (typing a URL or clicking a link)

    2. the web server has sent the requested page (that is; your website has sent the form)

    The next thing that takes place is that your user enters some data on the form. This data is not stored anywhere - if you refresh the page the data is gone, because steps 1 and 2 happen again.

    So to avoid this you can use a number of tools:

    Javascript: this operates on the user's computer. You can use it to find out if something has been entred on a form, and store it in, for example, a cookie.

    Then you will have to build some logic into your page that says, "if my user refreshes the page or comes back to this site at a later date, then look for the cookie. If it exists, then take it's values and pre-fill the form, before the user gets to see it."

    Server Side Script: This logic can be built into your web server (using a server side script like PHP) so it actually runs in step 2.

    Alternatively you can build it into a javascript function which fires when the page is actually received by your user. This would be a step 3.

    A second alternative combines these two ideas (processing on the user side and processing on the webserver side) called AJAX, which basically means that the "discussion" between your javascript and PHP takes place "on the fly" when the data is entered or changed.

    And lastly you might want to consider PHP Sessions to store data, and/or a mySQL database. Recently with the advent of modern browsers you now have the possibility to store the information in a local database available to your user's browser...

    In all of these cases you will need to learn how these pieces talk to each other, how you retreive the information, and how you update your stateless and static form.

    It isn't has straightforward as you might think...

    这篇关于可编辑的表格并保存更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆