Implement toastr in my contact form

1

How can I implement the Toastr JS in my contact form. I want to leave toastr.success and toastr.error instead of the alert() I have now.

This is my code:

<?php
if(isset($_POST['email'])) {

$email_to = "[email protected]";
$email_subject = "Mensaje de Mi Dominio";

if(!isset($_POST['nombre']) ||
!isset($_POST['email']) ||
!isset($_POST['mensaje'])) {

echo "<b>Ocurrió un error y el formulario no ha sido enviado. </b><br />";
echo "Por favor, vuelva atrás y verifique la información ingresada<br />";
die();
}

$email_message = "Detalles del formulario de contacto:\n\n";
$email_message .= "Nombre: " . $_POST['nombre'] . "\n";
$email_message .= "E-mail: " . $_POST['email'] . "\n";
$email_message .= "Comentarios: " . $_POST['mensaje'] . "\n\n";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

echo '<script languaje="javascript">
                alert("Mensaje Enviado");
            location.href="midominio.com";
            </script>';
    }else{
        echo '<script languaje="javascript">
            alert("Mensaje No Enviado");
            location.href="midominio.com";
            </script>';
    }
?>
    
asked by Eduardo HV 18.02.2017 в 16:59
source

1 answer

0

Here is an example: You can see it in fiddle .

Html

<input type="button" value="Error" id="error" />
<input type="button" value="Info" id="info" />
<input type="button" value="Warning" id="warning" />
<input type="button" value="Success" id="success" />
<br><br><br><br>

jQuery: You need to include the libraries, see resources in the fiddle link

$(function () {
    $('#error').click(function () {
        // make it not dissappear
        toastr.error("Noooo oo oo ooooo!!!", "Title", {
            "timeOut": "0",
            "extendedTImeout": "0"
        });
    });
    $('#info').click(function () {
        // title is optional
        toastr.info("Info Message", "Title");
    });
    $('#warning').click(function () {
        toastr.warning("Warning");
    });
    $('#success').click(function () {
        toastr.success("YYEESSSSSSS");
    });
});

Official example: link

    
answered by 18.02.2017 в 17:46