-3

I am trying to limit form submission to 15 minutes so the user must complete form submission within 15 minutes. The form is separated into two pages: details and payment so I guess the limit has to be set in the session. But I don't know where to start. I tried searching everything, but all results say how to limit form submission so user can only submit 5 times a day or so. Can anyone give me an example or links how to achieve this?

I am using laravel as a framework.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
z0mbieKale
  • 969
  • 1
  • 14
  • 44
  • `"I guess the limit has to be set in the session."` - Seems like a reasonable approach. When the form is first sent to the user, record the current timestamp in a session value. When the user submits the form, compare the now-current timestamp with the session-stored timestamp. – David Jul 17 '17 at 17:17
  • @David Can I show a timer somehow? – z0mbieKale Jul 17 '17 at 17:19
  • Of course. That part would be done in JavaScript, and there are many examples of JavaScript timers and countdowns available. – David Jul 17 '17 at 17:19
  • @David thank you sir. – z0mbieKale Jul 17 '17 at 17:20
  • For example with Jquery: https://github.com/jchavannes/jquery-timer – Fab Fuerste Jul 17 '17 at 17:21

3 Answers3

0

You must define how you want block the submit, IP? SessionId? LoggedUser?

After that you should save the last time post for the unique info and verify the info every time that post occurs

0

You can make timed submition by making the submition using ajax and when you open the page you can initial variable with the current time and when you click submit you can compare that variable with the current time if it less than 15 min you can make ajax submit or not you can do another something else

E-housma Mardini
  • 357
  • 1
  • 3
  • 21
  • 1
    AJAX is hardly necessary here. If the question isn't asking for that, introducing it is really adding unnecessary complexity and potentially confusing the person asking. – David Jul 17 '17 at 17:24
0

you can use JavaScript (or jquery lib) to countdown and disable submit button

function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        if (--timer < 0) {
            timer = duration;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 60 * 5,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};

<body>
    <div>Registration closes in <span id="time">05:00</span> minutes!</div>
</body>

to disable submit button change startTimer function like this:

if (--timer < 0) {
    timer = duration;
}else{
    // get button id and disable it or redirect page
}

to pass timer to second page you can add hidden input to your form and update it in function every time:

if (--timer < 0) {
    timer = duration;
    // here get hidden input id and update value
}else{
    // get button id and disable it or redirect page
}

countdown function from here: The simplest possible JavaScript countdown timer?

aidinMC
  • 1,415
  • 3
  • 18
  • 35