I made a form to send contact data (name, email, subject and message).
<form name="contactForm" id="form-contato" method="post">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="Nome" name="Nome" placeholder="Seu nome" value="" minlength="2" maxlength="50" required="" aria-required="true" class="full-width">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="Email" name="Email" placeholder="Seu e-mail" value="" required="" aria-required="true" class="full-width" required="required" type="email">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="Assunto" name="Assunto" placeholder="Assunto" value="" class="full-width">
</div>
<div class="form-field">
<textarea name="contactMessage" id="Mensagem" name="Mensagem" placeholder="Sua mensagem" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
</div>
<div class="form-field">
<input class="full-width btn--primary" type="submit" value="Enviar">
<div class="submit-loader">
<div class="text-loader">Enviando...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- contact-warning -->
<div class="message-warning">
Ops, aconteceu algum problema, atualize a página e tente novamente, obrigado!
</div>
<!-- contact-success -->
<div class="message-success">
Mensagem enviada com sucesso, obrigado!<br>
</div>
I am using a PHP script ( send_email
), but I can not trigger sending the form data.
My script was inserted before the tag was closed
<script>
// Variable to hold request
var request;
// Bind to the submit event of our form
$("#form-contato").submit(function(event){
// Prevent default posting of form - put here to work in case of errors
event.preventDefault();
// Abort any pending request
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
// Let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// Serialize the data in the form
var serializedData = $form.serialize();
// Let's disable the inputs for the duration of the Ajax request.
// Note: we disable elements AFTER the form data has been serialized.
// Disabled form elements will not be serialized.
$inputs.prop("disabled", true);
// Fire off the request to /form.php
request = $.ajax({
url: "send_email.php",
type: "post",
data: serializedData,
dataType: "json"
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
// Log a message to the console
console.log("Hooray, it worked!", response);
});
// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// Log the error to the console
console.error(
"The following error occurred: "+
textStatus, errorThrown
);
});
// Callback handler that will be called regardless
// if the request failed or succeeded
request.always(function () {
// Reenable the inputs
$inputs.prop("disabled", false);
});
});
</script>
This is the error generated in the console:
Can you help me?