Search code examples
mysqlhtmlexpressionengine

how to limit the Total Number of Form submissions per day


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 ?


Solution

  • 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.