Feedback message in php contact form

Asked

Viewed 381 times

0

Good evening, I have a contact form that’s working perfectly. However, after sending the email, the page turns white and I don’t have a feedback message. I’d like to display a modal with the message. Just follow my code:

<?php    
$nome = $_POST['nome'];
$email = $_POST['email'];
$cpf = $_POST['cpf'];
$moeda = $_POST['moeda'];
$valor = $_POST['valor'];
$local = $_POST['local'];
$formcontent=" Nome: $nome \n Email: $email \n CPF: $cpf \n Moeda: $moeda \n Valor: $valor \n Local: $local";
$recipient = "[email protected]";
$subject = "Contato Delivery SP";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

if ($formcontent == 1){ 
  echo "<script>$('#form-modal').modal('show')</script>"; 
}else{
  echo "<script>$('#form-modal-2').modal('show')</script>"; 
} 

?>
  • 1

    Okay, but what’s stopping you from doing that? Where’s the modal code? Is it bootstrap? Jquery UI?

  • @user5978 Yes. Bootstrap. The modal is right on the index.php page, I can call it from the console normally. But when sending the form, instead of opening the modal, open the empty page of sendmail.php (which is the page with this code from above)...

  • But where is this modal? in the form? When you send data via form (without ajax) the content of the page is "lost". Put the modal HTML (and the related library inclusion and dependencies) above the <?php... of the code you posted. I think it will work there ...

  • That line here doesn’t make much sense. if ($formcontent == 1){ - Surely it will never be one, for it is the text of the message.

1 answer

1


If you say a blank screen is being displayed, I imagine you are not using AJAX. In that case, you should keep in mind that the content of the page where the form is, after submission is fully "reset".

You should add that to the code

<!-- Inclusão das bibliotecas-->
<link rel....bootstra.css
<scr...bootstrap.js
<scr...jquery.js

<!-- código dos modals(ou ais) -->
<div class="modal-1"..
 ......
<div class="modal-2...
 ......

<!-- Aqui vai o script que você postou -->
<?php    
$nome = $_POST['nome'];
$email = $_POST['email'];
$cpf = $_POST['cpf'];
$moeda = $_POST['moeda'];
...

Browser other questions tagged

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