6
I made a script for subscription newsletter, the user sends the email to register.php and from there the script receives an echo in a message with button, the problem is that the button does not appear, what appears is the tag, see:
Script:
$(function()
{
$("#ok").click(function()
{
$("#formulario_news").hide("slow");
BeforeSend:$("#carregando_news").show("slow");
var email = $("#email").val();
$.post("<?php bloginfo('template_directory');?>/newsletter/cadastro.php",{email: email}, function(data)
{
complete:$("#carregando_news").hide("slow");
$("#retorno").show("slow").text(data);
$("#voltar").click(function()
{
$("#retorno").hide("slow");
$("#formulario_news").show("slow");
});
});
});
});
<div id="newsletter">
<h1>/Assine nosso newsletter</h1>
<div id="formulario_news">
<span>Informe seu email:</span>
<input type="text" id="email" name="email"/>
<input type="submit" name="ok" id="ok" class="btn_ok" value="OK"/>
</div>
<div id="carregando_news" style="display:none;">
<img src="<?php bloginfo('template_directory'); ?>/imagens/ajax-loader.gif"/> <p> Aguarde, enviando...</p>
</div> <!-- Carregando newsletter -->
<div id="retorno" style="padding:10px;border:1px solid #0F0;background:#C1FFD1;width:170px;margin-left:3px;margin-bottom:3px;display:none;font:14px Trebuchet;
font-weight:bold;">
</div>
</div>
php.:
$email = strip_tags(trim($_POST['email']));
if(empty($email))
{
echo "Informe seu email</br>";
echo "<button type="button" id="voltar"/>Voltar</button>";
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "Informe um email válido</br>";
echo "<button type="button" id="voltar"/>Voltar</button>";
}
Let’s assume that the user does not enter the email and click the OK button. The return is this:
Informe seu email</br>
<button type="button" id="voltar"/>Voltar</button>
Tags appear written, browser does not skip line and button does not appear.
I don’t know if this is the cause of the problem, but vc is using double quotes to delimit the string and using them inside the string:
"<button type="button" id="voltar"/>Voltar</button>"
– Sam
I ended up typing wrong here in the forum. But it was the method text(), have to use html().
– user122195