如何限制每天提交表单的总数

发布于 2024-11-09 08:41:32 字数 1195 浏览 0 评论 0原文

任何人都可以指导我如何设置在一天的特定时间段内启用的表单。

或者如何限制每天或每周等的表单提交总数。

例如,

我需要在一天或一小时内发送 100 个表单提交后自动禁用该表单。

应将 100 个提交添加到每天一桌。一旦发送了 100 个条目,该表格就在当天剩余时间内不再接受任何提交。

要求:我们每天需要处理一定数量的问题/提交。一旦某个表中的提交数量达到 100 或任何其他数字,则应禁用该表单。

我可以使用哪个 MySQL 查询?

或者可以通过 Javascript 禁用该表单吗?

这是一个简单的表格:

<p><label for="name">Name</label><br />
   <input type="text" name="name" value="name" id="name" size="37" /></p>

<p><label for="email">Email Address</label><br />
   <input type="text" name="email" value="email" id="email" size="37" /></p>

<p><label for="comment">Comment</label><br />
   <textarea name="comment" rows="8" cols="35" id="comment">comment</textarea></p>

<p><input type="submit" name="submit" value="Submit" /></p>

更新:感谢昆汀,

这是我达到的代码。

SELECT count(*) AS count FROM data where channel_id='2'"; 

if (count <= 100) {show the form} else {show a message that the form is closed} 

该表有3个字段, [年] [月] 和[天]。 当日期分为 3 个字段时,如何以这种方式使用 CURDATE() ?

Can anyone guide me as to how to set a form to be enabled for a certain time period in a day.

Or how to limit the Total Number of Form submissions per day or per week etc.

For e.g.

I need the form to automatically be disabled as soon as 100 form submissions have been sent in a day or an hour etc.

100 submissions should be added to a table per day. The form should not accept any more submissions for the rest of the day, as soon as 100 entries have been sent.

Requirement: We need to handle a certain number of questions/submissions per day. The form should be disabled once the number of submissions in a certain table reaches 100 or any other number.

Which MySQL Query can I use ?

Or can the form be disabled by Javascript ?

Here is a simple form:

<p><label for="name">Name</label><br />
   <input type="text" name="name" value="name" id="name" size="37" /></p>

<p><label for="email">Email Address</label><br />
   <input type="text" name="email" value="email" id="email" size="37" /></p>

<p><label for="comment">Comment</label><br />
   <textarea name="comment" rows="8" cols="35" id="comment">comment</textarea></p>

<p><input type="submit" name="submit" value="Submit" /></p>

Update: Thanks to Quentin

here is the code i have reached.

SELECT count(*) AS count FROM data where channel_id='2'"; 

if (count <= 100) {show the form} else {show a message that the form is closed} 

The table has 3 fields ,
[year]
[month]
and [day].
how do I use the CURDATE () in this manner as the date is divided into 3 fields ?

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

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

发布评论

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

评论(5

十级心震 2024-11-16 08:41:32

你不能做这个客户端。

类似以下的查询

select count(*) from myTable where myDateColumn >= CURDATE();

应该可以解决问题。

在决定是否应该生成表单以及决定是否应该接受表单提交时使用它。

You can't do this client side.

A query along the lines of:

select count(*) from myTable where myDateColumn >= CURDATE();

should do the trick.

Use it when deciding if you should generate the form, and when deciding if you should accept the form submission.

末蓝 2024-11-16 08:41:32

在显示表单的页面上:
查询数据库:在索引上使用 MySQL COUNT 来获取 num 行(1row = 1 个响应?),其中 Submitday = Today

查看以下链接,尤其是第二个,关于提取时间/日期
http://dev.mysql.com/doc/refman/5.1 /en/counting-rows.html

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

如果 numrows = 100
使用 javascript 'display:none' 你的表单,'display:block' 你的 div

On your page displaying the form:
Query your database: Use a MySQL COUNT on an index to get num rows (1row = 1 response??) where submitday = today

see the folloing links, esp the second, on extracting time/date
http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

if numrows = 100
use javascript to 'display:none' your form, 'display:block' your div

have <div id="toomuch" style="display:none;"><p>I'm sorry this form is closed for the day, try again tomorrow</p></div>

ㄖ落Θ余辉 2024-11-16 08:41:32

将时间字段添加到数据库中并使用 curdate 实例化,然后执行此查询

 SELECT count(id) from TABLE where DATA=CURDATE();

然后您可以在代码中实现一个函数来处理表单提交。

Add a time field to your database and instanciate with curdate then do this query

 SELECT count(id) from TABLE where DATA=CURDATE();

Then you can implements a function to in your code to handle the form submission.

执手闯天涯 2024-11-16 08:41:32

如果我理解正确,这是您网站上显示的表单(不是控制面板发布表单?) - 如果是这样,这相当简单。根据其他人在示例 SQL 语句中显示的时间戳,对数据库(如果您存储表单数据的位置)进行记录计数检查。当您达到限制时,您可以显示没有帖子值的表单,并使用 javascript & 禁用它。对其进行样式设置,使其看起来不可用(或不显示全部)。

在伪代码中:

Set timeframe  = week, day, etc.
Set maxsubmissions = 100 (or whatever)

Set sumbissioncount = Query db to get number of submissions within timeframe 

If submissioncount is less than maxsubmissions
 {embed form}
Else 
 {embed disabled form}
End if

注意给出的 sql 示例仅计算每天,而不是每周,例如,您必须修改一周 - 要使其通用,请在上面示例中的范围之间使用 Between 子句或 plunk 变量:请参阅相关线程: 日期范围查询MySQL

If I understand this right this is a form displayed on your website (not the control panel publish form?) - if so this fairly straightforward. Do a record count check on your DB (if that's where you're storing your form data) based on a timestamp as others have shown with the example SQL statement. When you're reached your limit you can display the form with no post value and disable it using javascript & style it so it looks un-usable (or don't display it all).

In pseudocode:

Set timeframe  = week, day, etc.
Set maxsubmissions = 100 (or whatever)

Set sumbissioncount = Query db to get number of submissions within timeframe 

If submissioncount is less than maxsubmissions
 {embed form}
Else 
 {embed disabled form}
End if

Note sql examples given will only count per day, not week, you'd have to modify that for a week for example - to make it generic use the between clause or plunk vars between the ranges in examples above: see related thread: Date Range Query MySQL

╰つ倒转 2024-11-16 08:41:32

以下代码有效:

SELECT count(*) AS count FROM `channel`

where `day` = DAY(CURDATE())

and `channel_id` = '2'

现在需要实时测试它是否适用于 CMS。表格是否隐藏。

如果我手动尝试编辑“ {if count <= '100'} ”,表单确实会隐藏,但我担心它是否会自动工作。我想我得等到早上。

The following code worked:

SELECT count(*) AS count FROM `channel`

where `day` = DAY(CURDATE())

and `channel_id` = '2'

Now it needs to be tested in realtime, if it works with the CMS or not. Does the form hides or not.

The form does hide if i manually try to edit " {if count <= '100'} " , the form does hide, but i am concerned if it will work automatically. I think ill have to wait till morning.

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