How to show your own message when a form has been submitted
<div class="formbackend-form-wrapper">
<form action="https://www.formbackend.com/f/kcsfk4qr" method="post" id="form-signup">
<label>Name</label>
<input type="text" name="name" minlength=2 required>
<label>Email</label>
<input type="email" name="email" required>
<button type="submit">Submit</button>
</form>
</div><script>
$(function() {
var $form = $('#form-signup');
var $formWrapper = $('.formbackend-form-wrapper');
$form.on("submit", function(e) {
var formUrl = $(this).attr('action');
// We don't want the page to submit and refresh
e.preventDefault();
// Let's show the user a message once they hit submit
$formWrapper.html("Submitting the form");
// POST the request to Formbackend (the formUrl value)
$.ajax({
url: formUrl,
type: 'POST',
headers : {
'accept' : 'application/javascript',
},
// We serialize the form fields
data: $form.serialize()
}).done(function(submissionMessage) {
// submissionMessage is the "Submission Text" you
// set in Formbackend
// - default: "We received your submission"
$formWrapper.html(submissionMessage)
}).fail(function() {
$formWrapper.html("Something went wrong :(")
}).always(function() {
// This always happens
});
});
});
</script>Last updated
Was this helpful?