Welcome Guest, Not a member yet? Register   Sign In
Prevent double insert at same time
#11

(This post was last modified: 01-16-2025, 11:27 AM by michalsn.)

A much cleaner way would be using
Code:
type="submit"

for your button, and then something like:

Code:
$("#myform").submit(function(e) {
    e.preventDefault();

    var scegli_materiali = $("#scegli-materiali").val();
    var quantita = $("#id_class_quantita").val();

    if (scegli_materiali == "") {
        alert('Scegli un codice!!!!');
    } else if (quantita == '') {
        alert('Inserisci una quantità');
    } else {
        $("#bottone_invio_form").prop("disabled", true);
        $("#bottone_invio_form").hide();
        $("#gif_animata").show();

        // Proceed with form submission
        this.submit();
    }
});


Anyway, for your existing code - try to add this in your final condition:

Code:
$(this).prop("disabled", true);

$(this).hide();

$("#gif_animata").show();

$("#myform").submit();

Oh... and consider whether it's worth taking advantage of the native validation you get when you use "required" tags in your input forms.
But I expect you have a reason for doing it the way you are doing it now.
Reply
#12

(This post was last modified: 01-17-2025, 12:17 AM by pippuccio76.)

(01-16-2025, 11:20 AM)michalsn Wrote: A much cleaner way would be using
Code:
type="submit"

for your button, and then something like:

Code:
$("#myform").submit(function(e) {
    e.preventDefault();

    var scegli_materiali = $("#scegli-materiali").val();
    var quantita = $("#id_class_quantita").val();

    if (scegli_materiali == "") {
        alert('Scegli un codice!!!!');
    } else if (quantita == '') {
        alert('Inserisci una quantità');
    } else {
        $("#bottone_invio_form").prop("disabled", true);
        $("#bottone_invio_form").hide();
        $("#gif_animata").show();

        // Proceed with form submission
        this.submit();
    }
});


Anyway, for your existing code - try to add this in your final condition:

Code:
$(this).prop("disabled", true);

$(this).hide();

$("#gif_animata").show();

$("#myform").submit();

Oh... and consider whether it's worth taking advantage of the native validation you get when you use "required" tags in your input forms.
But I expect you have a reason for doing it the way you are doing it now.

hi , i think that with this code i cannot resolve double insert on db , i must insert a validation to control if data with determinate condition are sending to db and if the time is equals i don't insert record...

i also think that ci developer must create a standard validation to prevent this by passing an array of value to control  (with created_at).
Reply
#13

No, checking the "created_at" field for the "equal times" is not the right direction, but good luck.
Reply
#14

(01-17-2025, 12:27 AM)michalsn Wrote: No, checking the "created_at" field for the "equal times" is not the right direction, but good luck.
created_at is not the right direction if i control only created at but if i control user_id and created_at at same time , how can an user insert two record at same time ?
Reply
#15

Because something isn't working correctly.

I was referring to the general idea. If you have to check if a record with the same data has not been added at the same time, then something is not working as it should.
If you really have to do this (for whatever reason), you should probably add a unique index to fields (user_id+created_at).
Reply
#16

I tink the problem is the server, i run my project on a Windows server with iis and some time it lost session and the user refresh and send post data twice , on 2024 only one time on 113.000 insertion but i would be rove the one too...
Reply
#17

Multiple ways of checking for form submission.

How to Prevent Users from Submitting a Form Twice
What did you Try? What did you Get? What did you Expect?

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

(01-25-2025, 04:19 AM)InsiteFX Wrote: Multiple ways of checking for form submission.

How to Prevent Users from Submitting a Form Twice
 i prevent client side submission or better i remove button onclick
Reply




Theme © iAndrew 2016 - Forum software by © MyBB