A <button>
element containing a <span>
is required.
The script will replace the text content of the <span>
when the form is submitted. The text specified in the data-loading-text
attribute on the <button>
will be shown momentarily while the
form is sent. This feature makes it easy to translate to other languages.
When the form is finished sending, the original text is restored.
Plain submit button
<button type="submit" class="btn btn-primary" data-loading-text="Sending">
<span>Subscribe</span>
</button>
Animated submit button
The <button>
can show an animation while the form is sending to the server.
- Add class
btn-loading
to the <button>
- Add an element with class
icon
to the button. It will be hidden by the theme's CSS.
<button type="submit" class="btn btn-primary btn-loading" data-loading-text="Sending">
<!-- Icon for loading animation (hidden by CSS) -->
<svg class="icon" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>Icon For Loading</title><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g><polygon points="0 0 24 0 24 24 0 24" opacity="0"></polygon></g><path d="M12,4 L12,6 C8.6862915,6 6,8.6862915 6,12 C6,15.3137085 8.6862915,18 12,18 C15.3137085,18 18,15.3137085 18,12 C18,10.9603196 17.7360885,9.96126435 17.2402578,9.07513926 L18.9856052,8.09853149 C19.6473536,9.28117708 20,10.6161442 20,12 C20,16.418278 16.418278,20 12,20 C7.581722,20 4,16.418278 4,12 C4,7.581722 7.581722,4 12,4 Z" fill="#000000" fill-rule="nonzero" transform="translate(12.000000, 12.000000) scale(-1, 1) translate(-12.000000, -12.000000) "></path></g></svg>
<span>Subscribe</span>
</button>
When the form is submitted, the class btn-loading-animate
will be added to the button, and the icon will be shown.
By default, the icon in the theme is animated by a CSS spin
animation.
When the form is finished sending, the btn-loading-animate
class will be removed from the button and the icon will be hidden.