Use ajax to display the message on sending email from forms.
<div id="form-result"></div>
<script>
$(document).ready(function(){
var form = $('#contact-home');
form.submit(function(e) {
// prevent form submission
e.preventDefault();
// submit the form via Ajax
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
dataType: 'html',
data: form.serialize(),
success: function(result) {
// Inject the result in the HTML
$('#form-result').html(result);
$('#button').text("Sent!");
}
});
});
});
</script>
“#form-result” is displayed, everything is fine.
But the button text in form is not changed after sending. Tell me how please.
Does $("#button span").text("Sent!"); work? I found that in this SO answer.
A nice UX would be to disable the button, perhaps with $("#button").prop("disabled",true);
BTW I haven’t tested the above.
@bleutzinn Interesting, I didn’t know that jQuery rendered a span inside a button.
If it does not work, what happen if you run it with $(’#button’).text(“Sent!”); first?
I think we would need to see your html too.
Once the form has successfully been submitted do you still want or need a button in the user interface? I suppose not, so you can simply add a text message in a (new) div that says “Sent !” or something like that.
Block message sending works. But recently saw on the website a send button with a animation inside and a change of labels after posting. I think it is very modern and looks very cool.
I don’t think you can set an id from the frontmatter for this field as id don’t work everywhere.
try adding a unique class instead or call one of these existing class.