Changing the Output of a <form> - Redirect to Another Upload Page

Asked

Viewed 127 times

1

Hello,

I have a form and I’d like to know how to change his results.

Example: both when the form is successfully completed and when an error occurs it redirects to a page of my choice.

I’m using the following code:

<form class="mbr-form" action="[email protected]" method="post" name="Meu Formulario">
      <div class="row row-sm-offset">
          <div class="col-md-4 multi-horizontal" data-for="name">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="name">Nome</label>
                   <input type="text" class="form-control" name="name" data-form-field="Name" required>
              </div>
          </div>
          <div class="col-md-4 multi-horizontal" data-for="email">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="email">Email</label>
                   <input type="email" class="form-control" name="email" data-form-field="Email" required>
              </div>
          </div>
          <div class="col-md-4 multi-horizontal" data-for="phone" hidden="hidden">
              <div class="form-group">
                   <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="phone" hidden="hidden">Produto</label>
                   <input type="tel" class="form-control" name="phone" data-form-field="Phone" hidden="hidden">
              </div>
          </div>
      </div>
      <div class="form-group" data-for="message">
          <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="message">Mensagem</label>
          <textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message"></textarea>
      </div>

      <span mbr-buttons mbr-theme-style="display-4" data-toolbar="-mbrLink,-mbrBtnAdd,-mbrBtnMove" class="input-group-btn"><a href type="submit" class="btn btn-primary btn-form">ENVIAR MENSAGEM</a></span>
  </form>
  • What do you want with this code? Send the data to the email [email protected]?

  • Yes, exactly. And after sending the data to the email, I would like to direct the user to an external page (example: www.google.com)

  • You have php support?

  • This form does not support php. This form was created with Formoid (http://formoid.com)

  • I didn’t know this formoid. What I wanted to ask is if your server has PHP.

  • Yes, it has a PHP server.

  • Why phone is Hidden?

Show 2 more comments

1 answer

1

HTML

<form class="mbr-form" action="" method="post" name="Meu Formulario">
  <div class="row row-sm-offset">
      <div class="col-md-4 multi-horizontal" data-for="name">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="name">Nome</label>
               <input type="text" class="form-control" name="name" data-form-field="Name" required>
          </div>
      </div>
      <div class="col-md-4 multi-horizontal" data-for="email">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="email">Email</label>
               <input type="email" class="form-control" name="email" data-form-field="Email" required>
          </div>
      </div>
      <div class="col-md-4 multi-horizontal" data-for="phone" hidden="hidden">
          <div class="form-group">
               <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="phone" hidden="hidden">Produto</label>
               <input type="tel" class="form-control" name="phone" data-form-field="Phone" hidden="hidden">
          </div>
      </div>
  </div>
  <div class="form-group" data-for="message">
      <label mbr-text class="form-control-label mbr-fonts-style" mbr-theme-style="display-7" for="message">Mensagem</label>
      <textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message"></textarea>
  </div>

 <input type="submit" class="btn btn-primary btn-form">
</form>

Simple email submission script with PHP

if(isset($_POST['email'])) {
  $to = "[email protected]";
  $subject = "Form";
  $name = $_POST['name'];
  $email= $_POST['email'];
  /********o input phone está hidden *******/
  $phone = $_POST['phone'];
  $message = $_POST['message'];

  $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";

    if(mail($to, $subject, $body)){
       header('Location: http://www.google.com');
    }else{
       echo "Erro no envio";
    }
}

A good email submission script is Phpmailer

    /******* CODIGO EMAIL *******/

    /* Uma dica para envio de emails
    Baixe os arquivos  PHPMailerAutoload.php - class.smtp.php -  class.phpmailer.php
    em github - https://github.com/PHPMailer/PHPMailer/tree/5.2-stable
    Crie uma pasta  PHPMailer-master no mesmo diretório da sua aplicação PHP e 
    publique os arquivos baixados nesta pasta (PHPMailer-master).
    */
if(isset($_POST['email'])) {    

    $nome = $_POST['nome'];

    $email = $_POST['email'];

    $celular = $_POST['phone'];

    $mensagem = $_POST['message'];

    //email Destinatario
    $emailDest = "[email protected]";

    $email = Trim(str_replace("'","",$email));


    require_once 'PHPMailer-master/PHPMailerAutoload.php';

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = 'smtp.dominio.com';
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->IsHTML(true);
    $mail->Username = '[email protected]';
    $mail->Password = 'senha';

    //$mail->SMTPSecure = false; //Diz que nao tem tls/ssl
    $mail->SMTPSecure = 'tls';  
    //$mail->SMTPAutoTLS = false; //Diz que nao tem tls/ssl

    //$mail->SMTPDebug = 2; //Mostra os bugs

    //E-mail remetente
    $mail->From = $email;

    //Nome do remetente
    $mail->FromName = $nome;

    //Assunto da mensagem
    $mail->Subject = "teste mail";

    //Corpo da mensagem
    $mail->Body = "Celular ".$phone." - Mensagem ".$mensagem;

    //Corpo da mensagem em texto
    //$mail->AltBody = 'Conteudo do e-mail em texto';


    //Destinatario 
    $mail->AddAddress ($emailDest);

    $mail->Send();

}

Browser other questions tagged

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