Redirect after php Action

Asked

Viewed 907 times

1

The customer form, just sent emails, now I need that in addition to send the emails, the data is stored in the database, this I was able to perform, so my html :

  <form action="insert.php" method="post">
                            <h4>Seus dados:</h4>
                            <input type="text" name="Nome" placeholder="Nome..." class="quote-form-element" />
                            <input type="text" name="Cidade" placeholder="Cidade/UF..." class="quote-form-element quote-form-client-email last" />
                            <input type="text" name="Telefone" placeholder="Telefone..." class="quote-form-element telefone" />
                            <input type="text" name="Email" placeholder="E-mail..." class="quote-form-element quote-form-client-email last contact_email"
                            />                                

                            <button class="button button-navy-blue send-quote" type="submit">Simular meu consórcio <i class="fa fa-paper-plane-o"></i></button>



                            <div class="quote-form-thanks">

                                <div class="quote-form-thanks-content">

                                    Obrigado pelo seu interesse, retornaremos em breve ;).
                                    <span class="quote-form-thanks-close">Fechar</span>

                                </div>
                        </form>

PHP to save data to mysql

<?php
$con = mysql_connect("localhost","***","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("novo", $con);

$sql="INSERT INTO tablename (nome, cidade, telefone, email )
VALUES
('$_POST[Nome]','$_POST[Cidade]','$_POST[Telefone]','$_POST[Email]')";

if (!mysql_query($sql,$con))


mysql_close($con)
?>

PHP email

$title = 'Nova simulação via website';


        $headers = "MIME-Version: 1.1\n".
                   "Content-type: text/html; charset=utf-8\n".
                   "Content-Transfer-Encoding: 8bit\n".
                    "From: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
                   "Reply-to: ". $_POST['clientName'] ." <". $_POST['clientEmail'] .">\n".
                   "Date: ". date( "r" ). "\n";


        $values = $_POST['values'];


        $rows = '';
        if (count($values) > 0) {
        for( $i = 0; $i < count( $values ); $i++ ) {

            $rows .= '<tr>

                          <td style="width: 200px; font-weight: bold; border: 1px solid #eee; padding: 10px;">'. $values[$i]['name'] .'</td>
                          <td style="border: 1px solid #eee; padding: 10px;">'. $values[$i]['value'] .'</td>

                      </tr>';
        }


        $content = '<table style="width: 600px; font-size: 11px; border-collapse: collapse;">'. $rows .'</table>';


        $result = mail(
            OWNER_EMAIL,
            "=?UTF-8?B?". base64_encode( $title ) ."?=",
            $content,
            $headers
        );}

JS email

 $(".send-quote").click(function() {
    var a = $(this).parent(),
        b = a.parent().parent(),
        d = (b.data("quote-form-for"), {}),
        f = "",
        g = "",
        h = "",
        i = "",
        j = !1;
    a.find(".quote-form-element").each(function(a) {
        f = $(this).attr("name"), "undefined" != typeof f && f !== !1 || (f = $(this).data("name")), $(this).hasClass("checkbox") ? g = "yes" == $(this).data("checked") ? $(this).children(".checkbox-values").children(".checkbox-value-checked").text() : $(this).children(".checkbox-values").children(".checkbox-value-unchecked").text() : (g = $(this).is("input") || $(this).is("select") ? $(this).val() : $(this).text(), $(this).is("input") && "" == g || $(this).is("select") && "-" == g ? (j = !0, $(this).addClass("error")) : $(this).removeClass("error")), $(this).hasClass("quote-form-client-name") && (h = $(this).val()), $(this).hasClass("quote-form-client-email") && (i = $(this).val()), d[a] = {
            name: f,
            value: g
        }, a++
    }), 0 == j && $.ajax({
        url: "_assets/submit.php",
        data: {
            send: "quote-form",
            values: d,
            clientName: h,
            clientEmail: i
        },
        type: "post",
        success: function(b) {
            a.children(".quote-form-thanks").fadeIn(300)
        }
    })
}), $(".quote-form-thanks-close").click(function() {
    var a = $(this).parent().parent();
    a.fadeOut(300)
}),

After submitting the form, it redirects to the `Insert.php.

When I just sent the email, it would display a message that was sent on the same page, and then the user would close the form.

You’d think he wouldn’t redirect?

If you want to see what the page looks like, here

  • Actually I answered,and now reading again I don’t quite understand what you want... Do you want it not to redirect ? What exactly do you want ? You want the action point to the same page ? or how ?

  • Where is the email sending code? I think I’m starting to understand,,,

  • @Magichat edited the question, put the codes. I do not even know if it is possible to send to email and store in BD. What I would really like it to work, is that the message that was sent, remains, as occurs on the page

2 answers

1

You can add it to your file insere.php a redirect :

if (!mysql_query($sql,$con))
header("location:pagina_destino.php");

0

Complementing what our friend @Magichat said..

You can also customize with a alert:

alert('SUA MENSAGEM AQUI'); 
window.location='index.php';

Getting like this in PHP

if (!mysql_query($sql,$con)) echo "<script type='text/javascript'>alert('SUA MENSAGEM AQUI'); window.location='index.php'; </script>";

Browser other questions tagged

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