Disable button on click but still process the form

I want to disable my register button on click to prevent spam, but I don't want the form that the button is submitting from submit.

I can disable the button on click, but I can't figure out why the form won't submit yet ...

button:

<?= form_open("course/registerCourse", "method='post'") ?>
   <input type="hidden" name="session" value="<?= $session["id"] ?>">
   <button type="submit" class="btn-sm btn btn-success register">REGISTER</button>
<?= form_close() ?>

      

JQuery

$('.register').on('click',function() {
    $(this).prop("disabled",true);
    $("form").submit();
});

      

Registration function:

public function registerCourse()
{

    $user = $this->users_model->userAccountTP();
    $appParticipant = $user[0]["id"];

    $author_id = $this->session->userdata("ci_user_id");
    $appSession = $this->input->post('session');

    $this->ci_channel_entry_model->save_multiple(array(
        "channel_id" => 11,
        "title" => date("Y-m-d h:i:s"),
        "author_id" => $author_id,
        "status_id" => 7,
        "date" => date("Y-m-d h:i:s"),
        "data" => array(
            array(
                // application-session
                "field_id" => 28,
                "content" => $appSession
            ),
            array(
                // application-participant
                "field_id" => 29,
                "content" => $appParticipant
            )
        ),
        "hook" => FALSE
    ));

    redirect($this->agent->referrer());
}

      

+3


source to share


2 answers


Ended up reworking my form to agree with this answer and everything worked:



fooobar.com/questions/93961 / ...

+1


source


I think you might have a typo, because I don't see where you are declaring $form

, so maybe this helps:



$('.register').on('click',function() {
    $(this).prop("disabled",true);
    $("form").submit();
});

      

+4


source







All Articles