将提交的表单内容直接发布到页面

发布于 2024-11-30 22:30:41 字数 2325 浏览 2 评论 0原文

我有一个非常基本的表单,仅包含两个下拉框(尽管第二个下拉框的内容根据第一个下拉框的选择而变化)。然后,一旦做出选择,我就会在第二个下拉框下显示一些文本,并且文本所说的内容对于所做的任何选择都是唯一的。

我想要做的是将这些信息直接发布到一个表格中,一旦用户点击提交按钮,该表格将包含在表单所在同一页面的底部。换句话说,当用户提交表单时,我不希望它只是将用户的信息吐回给他们;我希望信息实际发布到表中的页面,以便任何登录的人都可以看到它,并且也可以将自己发布的信息添加到表中。

您可以将其视为有点像博客评论系统,每次访问者提交表单时都会自动将新内容发布到页面,除了允许用户插入他们想要的任何内容的文本区域之外,我有下拉框,只允许他们选择某个选项,然后将所选信息发布到表中。

我该怎么做呢?我对PHP有初学者的了解,对javascript几乎没有了解。但根据可能提供的答案的详细程度和帮助程度,我可以使用其中任何一个。

此表单仅可供登录的会员访问,并且我希望在每次用户点击“提交”时将 6 位信息发布到表中的一行 6 列中。这 6 件事是:(1)用户名,(2)时间戳(提交表单的日期和时间),(3)第一个下拉列表的选择结果,(4)第二个下拉列表的选择结果,(5)根据第二个下拉列表中的任何选择显示的唯一文本,以及 (6) 第二个时间戳,计算为第二列中生成的时间之后 30 天。

任何帮助将不胜感激。我正在尝试使用 PHP,但我的知识确实还不够先进,还不足以真正让我自己在任何地方取得进步。

编辑:

我之前做了一些尝试并做了一些更改。 。第三,我有一个包含以下 4 个表的数据库:

table: Members

  • member_id
  • Firstname
  • Lastname
  • Login
  • PasswdRank_id
  • 首先,我现在想要 1 个下拉框,而不是 2 个。其次,表中有 9 列,而不是 6列

表:排名

  • ID
  • 名称

表: 职位

  • ID
  • 名称
  • 要求_1
  • 要求_2
  • 要求_3
  • 工资
  • 排名_ID

表: 工单

  • 日期
  • 用户名
  • 排名
  • 职位
  • 要求_1
  • 要求_2
  • 要求_3
  • 工资
  • 到期日期

这是我当前的网站正在处理:http://www.kiithsoban.com/membership

您可以使用访客登录来获取访问权限:

  • 用户名:用户名
  • 密码:密码

这是为在线游戏部落(在《EVE Online》中)制作的个人项目,每月可能有 20 个唯一访客,因此质量和正确的编码技术并不是什么大问题(不是在这个问题上)无论如何点)。主要关心的只是它是否有效。

我建议发布 PHP 表而不是采用 javascript 路线的原因是因为我已经在数据库中创建了一个表(而且我也更熟悉 PHP,只想尽快获得此在线版本的第一个版本),并且我也已经将其发布到网站上,正如您在上面的页面上看到的那样。这是“工作指令”表。

登录后您会注意到索引页面上有一些说明涉及下拉框,但该下拉框尚不存在。下拉框将包含 49 个可供选择的“工作”。当用户选择一个选项并提交表单时,我希望他们的选择插入到我的数据库中工作订单表的“作业”字段中;而且,我还希望网站能够检测其他 8 个字段中的附加信息,以便自动插入它们。

我一直在尝试一个想法,但我不确定它是否有效,或者如何准确地做到这一点。在我的会员和职位表中,我包含了一个“rank_id”字段,其中每个条目都将具有与排名表中的“id”字段匹配的值。现在,有 49 个“工作”可供选择,但是,根据用户的级别,他们的工作薪水会有所不同(假设有 7 个级别,则 49 * 7 = 343 种可能的工作/薪水组合总计为表单提交)。我希望网站做的是检测登录用户的“rank_id”(在members表中),当用户从下拉列表中选择一个职位后,在jobs表中找到具有相同“rank_id”的相应职位。我假设,这将允许网站收集“用户”、“排名”、“第一要求”、“第二要求”、“第三要求”和“薪水”信息(所有这些都包含在成员和职位表),然后将该信息插入工作订单表中的相应字段中,以便该信息随后发布到站点。

那时,我需要担心的是“日期”和“截止日期”列 - 提交表单时自动生成“日期”作为当前日期,并且“截止日期”自动计算为当前日期加上 30 天。

我希望这是一个更有用的解释,而不是太令人困惑。

I have a very basic form consisting of only two dropdown boxes (though the contents of the second dropdown vary depending on the selection made in the first). I then have a bit of text that displays under the second dropdown box once a selection has been made, and what the text says is unique to whatever selection is made.

What I want to be able to do is have this information directly publish into a table that will be included at the bottom of the same page the form is located on, once a user hits the submit button. In other words, when a user submits the form, I don't want it to simply spit the user's info back to them; I want the info to actually publish to the page in a table, so that anyone who logs in can see it, and can add their own published info to the table as well.

You could think of it sort of like a blog commenting system that automatically publishes new content to the page every time a visitor submits the form, except, instead of text areas that allow users to insert whatever they want, I have dropdown boxes that only allow them to select a certain option, and then have that selected info publish to a table.

How would I go about doing this? I have a beginner's knowledge of PHP, and almost no knowledge of javascript. But depending on how detailed and helpful of an answer that may be provided, I could work with either.

This form is only accessible to members who are logged in, and I have 6 bits of info that I want to have published into a row of 6 columns in the table every time a user hits Submit. Those 6 things are: (1) Username, (2) Time Stamp (Date & Time at which the form was submitted), (3) Selection result of 1st Dropdown, (4) Selection result of 2nd Dropdown, (5) The unique text that is displayed according to whichever selection is made in the 2nd dropdown, and (6) a second time stamp which is calculated as 30 days beyond the time generated in the 2nd column.

Any help would be appreciated. I'm experimenting with PHP a bit but my knowledge is really not advanced enough yet to really allow me to progress much of anywhere on my own.

EDIT:

I did some playing around earlier and have made a few changes. First, I'm now wanting 1 dropdown box, not 2. Second, there are 9 columns in the table, not 6. Third, I have a database with the following 4 tables:

table: members

  • member_id
  • firstname
  • lastname
  • login
  • passwd
  • rank_id

table: ranks

  • id
  • name

table: jobs

  • id
  • name
  • requirement_1
  • requirement_2
  • requirement_3
  • salary
  • rank_id

table: workorders

  • date
  • username
  • rank
  • job
  • requirement_1
  • requirement_2
  • requirement_3
  • salary
  • due_date

Here is the current site I am working on: http://www.kiithsoban.com/membership

You may use a guest login to gain access:

  • Username: username
  • Password: password

This is a personal project made for an online gaming clan (in EVE Online), with all of maybe 20 unique visitors a month, so quality and proper coding technique is not much of an issue (not at this point anyway). The primary concern is simply that it will work.

The reason I suggested posting a PHP table rather than taking the javascript route is because I already have a table created in a database (and I'm also more familiar with PHP and just want to get the first version of this online ASAP), and I already have it posting to the website as well, as you'll see on the above page. This is the "workorders" table.

You'll notice upon logging in that there are instructions on the index page referring to a dropdown box, which does not yet exist. The dropdown box will consist of 49 "jobs" to select from. When a user selects an option and submits the form, I want their selection to insert into the "job" field of the workorders table on my database; and, I also want the site to detect the additional information in the other 8 fields in order to automatically insert them as well.

I've been experimenting with one idea, but I'm not sure if it would work, or how to do it exactly. In my members and jobs tables, I've included a "rank_id" field, in which each entry will have a matching value to the "id" field in the ranks table. Now, there are 49 "jobs" to choose from, however, depending on what rank a user is, their job salary will vary (given that there are 7 ranks, 49 * 7 = 343 total possible job/salary combinations that can result from the form submission). What I want the site to do is detect the logged in user's "rank_id" (in the members table), and after the user selects a job from the drop down, find the corresponding job in the jobs table that has the same "rank_id". That, I'm assuming, would allow the site to gather the "User", "Rank", "1st Requirement", "2nd Requirement", "3rd Requirement", and "Salary" info (all of which are contained in the members and jobs tables), and then insert that info into the appropriate fields in the workorders table, so that the info will then post to the site.

At that point all I would need to worry about are the "Date" and "Due By" columns - the "date" being automatically generated as the current date when the form is submitted, and the "due by" being automatically calculated as the current date plus 30 days.

I hope that's a more helpful explanation, and not too confusing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-12-07 22:30:41

您需要为表单创建一个 OnSubmit 事件,该事件将在 javascript 函数内返回 false。然后该函数需要将内容添加到页面。如果您提供布局,我会提供更详细的代码。

You will need to create an OnSubmit event for the form which will return false inside the javascript function. The function will then need to add the content to the page. I would give more detailed code if you provided a layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文