Hide (or disable) submit button when user clicks on it
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.
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 recommend using jQuery to handle this
Try:
<input data-disable-with="Saving..." name="commit" 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.
精彩评论