单击时禁用按钮但仍处理表单

时间:2015-06-03 20:54:40

标签: javascript php jquery html forms

我想在点击时禁用我的注册按钮以防止垃圾邮件,但我不想阻止按钮提交的表单提交。

我可以在点击时停用按钮,但无法弄清楚表单仍然无法提交的原因......

按钮:

<?= 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();
});

注册功能:

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());
}

2 个答案:

答案 0 :(得分:4)

我想你可能有一个错字,因为我看不到你宣布$form的位置,所以这可能会有所帮助:

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

答案 1 :(得分:1)

结束重新处理我的表单以符合这个答案,一切正常:

https://stackoverflow.com/a/5691065/4141833