Message while form is being sent

Asked

Viewed 70 times

0

Good night, you guys, I have a form in php that with the option to attach file and then will be sent to an email, I am beginner in this part of ajax and javascript but I wonder if it has how to display a message while the form is "sent" if it is javascript or only with ajax, if anyone has examples thank you

 <form method="post" action="script/trab_send.php" id="form_trab" onsubmit="return validar(this)" autocomplete="off" enctype="multipart/form-data">
                        <input type="text" class="box" placeholder="NOME*" id="nome" name="nome" pattern="[A-Za-zÀ-úÂ-ûÃ-õ]+$" required>
                        <input type="email" class="box" placeholder="E-MAIL*" name="email" required>
                        <input type="tel" class="box" placeholder="TELEFONE*" name="fone" required pattern="\([0-9]{2}\) [0-9]{4}-[0-9]{4,5}$" OnKeyPress="mascara(this)" maxlength="15">
                        <input id="fakeupload" name="fakeupload" class="fakeupload" type="text" placeholder="ANEXAR ARQUIVO" />
                        <input id="realupload" name="realupload" class="realupload" type="file" progress onchange="this.form.fakeupload.value = this.value;" />
                        <input type="submit" value="Enviar" class="btn-ajuda">
                    </div>
                </form>
            <div class="resposta"></div> `=$_FILES['realupload'];

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->Port = 587;
$mail->CharSet = 'UTF-8';
$mail->Host = '';
$mail->Username = '';
$mail->Password = '';
$mail->SetFrom('');
$mail->AddAddress('');
$mail->Subject = '';
$mail->IsHTML(true);
$mail->Body=$body;
$body = "<strong>Arquivo: </strong>{$arquivo['name']}";

$mail->MsgHTML($body);
$mail->AddAttachment($arquivo['tmp_name'], $arquivo['name']);



 if($mail->Send()){
echo "<div class='sucesso'>Formulário enviado com sucesso! Em breve entraremos em contato!</div>";

$(document).ready(function(){
        $(".resposta").hide();
        $("#form_trab").ajaxForm({
            target: '.resposta',
            success: function(retorno){
                $(".resposta").html(retorno);
                $(".resposta").show();
            }
    });`

1 answer

0


Add a div with the "message id"

$("#form_trab"). on("subimit", Function(){ $("#message"). html("Form is being sent."); })

  • I did a test here, it worked cool, thanks brother

Browser other questions tagged

You are not signed in. Login or sign up in order to post.