Welcome Guest, Not a member yet? Register   Sign In
Multiple record insertion prevent
#1

HI , sorry for english , if i press send form button several time i have an insertion for every  button press , how can i prevent it?
Reply
#2

How to prevent form from submitting multiple times from client side?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(07-09-2021, 05:25 AM)InsiteFX Wrote: How to prevent form from submitting multiple times from client side?

Validation prevent form submitting ? Or must i use ever js ?
Reply
#4

Code:
prevent  with js
function () {
$("#personal_information").submit(function (e) {
e.preventDefault();

var url = $(this).attr('action');
var postData = $(this).serialize();


$.post(url,
postData
,
function (data, status) {

var w = JSON.parse(data);
console.log(w);
if (w.result == 1) {

var output = forgotMessageSuccess2(w.message);

var aboutme = document.getElementById("aboutme").value;
document.getElementById("aboutmetext").innerHTML = aboutme;
$("#forgotbanner5").empty();
$("#forgotbanner5").append(output).fadeIn(1000);


timeout('#forgotbanner5');


} else {
var output = forgotMessageFaill2(w.message);


$("#forgotbanner5").empty();
$("#forgotbanner5").append(output).fadeIn(1000);
timeout('#forgotbanner5');

}


});


});

};
Enlightenment  Is  Freedom
Reply
#5

disable button after press (use JS)
Reply
#6

Disabling the button with JS is good for the client side validation and for UX (user experience). But you can also add a CSRF token to your form to reject the other requests. Only the first one will have a valid token and the other will be rejected. Some people (or bots) disable JS, so it's always a good idea to validate data on the server.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB