admin 管理员组

文章数量: 1086019

I am working on development of an application using CakePHP framework.

We all have clients that click several times on the submit button.

How can I hide or (even better) disable the submit button when a user clicks on it?

On the internet I found several Javascripts that can do it, but I need help to integrate it into my CakePHP script.

I am working on development of an application using CakePHP framework.

We all have clients that click several times on the submit button.

How can I hide or (even better) disable the submit button when a user clicks on it?

On the internet I found several Javascripts that can do it, but I need help to integrate it into my CakePHP script.

Share Improve this question edited Sep 26, 2010 at 16:48 Marcel Korpel 21.8k6 gold badges62 silver badges80 bronze badges asked Sep 26, 2010 at 15:10 user198003user198003 11.2k30 gold badges98 silver badges153 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

Put this on the submit button:

onclick="this.disabled=true;return true;" 

example

    <input type=submit value='submit'
onClick='this.disabled=true;doSection(loading);return true;'> 

using jquery

 $("form").submit(function() {
            $(":submit", this).attr("disabled", "disabled");
          });

To follow up on what JapanPro said, if you want to place an onClick event in your submit field then you will need to use the form helper's submit function instead of the end() function. (CakePHP 1.2)

<?php echo $form->submit('Submit', array('onClick' => 'alert("Test");')); ?>

This also means you will need to manually close the form.

</form>

Id remend using jQuery to handle this

Try:

<input data-disable-with="Saving..." name="mit" type="submit" value="Create new item">

Note the

data-disable-with="Saving..."

I've tried every suggestion on the web, including the ones above, and this is the only thing that seems to work on all browsers. I'm using CakePHP 1.2.

echo $form->submit('Submit', array('onClick' => 'this.disabled=true;this.form.submit();return true;'));

Hope this helps.

本文标签: javascriptHide (or disable) submit button when user clicks on itStack Overflow