Is it possible to create a mailto with SweetAlert?

0

I'm doing a web page, and I'd like to add a mailto (send an email), through SweetAlert, but it gives me an error and disables some dynamic buttons that I have. Does anyone know if it is possible to do it? I enclose my code in case you can help me. I have been checking, and I just get an error with the form in the JS. If I change the label and put a title (h2, for example), I do not get an error.

Thanks in advance!

JS:

$("#email").on("click", function (){
            swal({
                allowOutsideClick: false,
                title: '¡Enviame un correo!',
                html: "<form action="mailto:[email protected]?subject=Contacto%20pag%20Web" method="post" enctype="text/plain">Nombre:<br><input type="text" name="name"><br>E-mail:<br><input type="text" name="mail"><br>Commentarios:<br><input type="text" name="commentarios" size="50"><br><br><input type="submit" value="Send"></form>"
            })  
        })

HTML:

<!-- Botón contactame -->
            <button class="btn boton2" title="Enviar correo"><a href="#" id="email" class="estiloboton"><i class="far fa-envelope"></i></a></button>
    
asked by Miquel Puente 23.07.2018 в 13:09
source

2 answers

0

your mistake is here to use double collines in everything and it should not be like that, you should only make double quotes and inside of it there should be single quotes:

"mailto:[email protected]?subject=Contacto%20pag%20Web" method="post" enctype="text/plain">Nombre:<br><input type="text" name="name"><br>E-mail:<br><input type="text" name="mail"><br>Commentarios:<br><input type="text" name="commentarios" size="50"><br><br><input type="submit" value="Send"></form>

I recommend you read this:

what-difference -hay-entre-doble-comilla-y-comillas-simples-y

and if you want to implement a contact form with sweetalart you can look at this github gits:

gits example

a similar question in stackoverflow in English:

sweet-alert-with-form-js-3-input

You can also use swal-forms to create one:

swal-forms , look at one in action:

demo

    
answered by 23.07.2018 / 13:27
source
0

Your error is that the double quotes inside the html attribute, since it is a string that has special characters, must go with backslash or, alternatively, change them by single quote.

$("#email").on("click", function (){
            swal({
                allowOutsideClick: false,
                title: '¡Enviame un correo!',
                html: "<form action=\"mailto:[email protected]?subject=Contacto%20pag%20Web\" method=\"post\" enctype=\"text/plain\">Nombre:<br><input type=\"text\" name=\"name\"><br>E-mail:<br><input type=\"text\" name=\"mail\"><br>Commentarios:<br><input type=\"text\" name=\"commentarios\" size=\"50\"><br><br><input type=\"submit\" value=\"Send\"></form>"
            })  
        })
    
answered by 23.07.2018 в 13:19