I want to disable my register button on click to prevent spam, but I don't want to prevent the form the button submits from submitting.
I'm able to disable the button on click, but can't figure out why the form still won't submit...
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();
});
register 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());
}
I think you might have a typo, because I dont see where you are declaring $form, so maybe this helps:
$('.register').on('click',function() {
$(this).prop("disabled",true);
$("form").submit();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With