0

I am pretty new to HTML forms, but I am trying to limit 1 submit request per user, per day. So I don't have any people spam it. I am not the best coder, but not the worst.

Example (in words, not code):
If user has not submitted the form today:
Form allows person to submit.

If user HAS submitted the form today:

Form does not allow person to submit form, notifies them as well.

Please note this in HTML and JavaScript only please!

TheC0der
  • 1
  • 1
  • Possible duplicate of https://stackoverflow.com/questions/13495833/limit-the-number-of-time-a-form-can-be-submitted – koolkat Aug 25 '17 at 22:34
  • 2
    These should be done server side – MinusFour Aug 25 '17 at 22:34
  • 1
    You will need some sort of storage to know if that client has submitted the form already and since you only want this in html/js you could use local storage/cookie but the client can simply clear browser data and submit again or use a different browser to submit so doing this client-side will have issues and will not guarantee what you are wanting. – NewToJS Aug 25 '17 at 22:35

2 Answers2

0

I do not think that you can do this with only client side technologies (like HTML and JS) since they're session based. If a user opens a different browser or even closes and opens the same browser, the JS and HTML are 'new' again. You could limit it per browser if you used a client side cookie that stored the submission and the time stamp, but it would not prevent the user from submitting again using a different browser.

Here is a link about cookie creation and reading: Set cookie and get cookie with JavaScript

0

html and js only solution:

if (confirm("have you made a request today? 'OK' means YES, and 'Cancel' means No")) {
  document.getElementById("submitBtn").disabled = true;
} else {
  document.getElementById("submitBtn").disabled = false;
}
<form>
  First name:<br>
  <input type="text" name="firstname"><br> Last name:<br>
  <input type="text" name="lastname"><br>
  <button type="submit" id="submitBtn">Submit</button>
</form>

yah, not really possible. sessions or cookies can be easily bypassed as others mentioned...

You could try to prevent spam with a captcha.

user7552
  • 315
  • 1
  • 3
  • 19