I need to get a value from a php session that is on a page where I have a contact form and pass through Ajax to another page, on that page I check whether the values are the same or not, but I can not do .
My captcha code creates the session view:
<?php
session_start();
$codigoCaptcha = substr(md5( time()) ,0,9);
$_SESSION['captcha'] = $codigoCaptcha;
$imagemCaptcha = imagecreatefrompng("fundocaptch.png");
$fonteCaptcha = imageloadfont("anonymous.gdf");
$corCaptcha = imagecolorallocate($imagemCaptcha,127,82,53);
imagestring($imagemCaptcha,$fonteCaptcha,15,5,$codigoCaptcha,$corCaptcha);
header("Content-type: image/png");
imagepng($imagemCaptcha);
imagedestroy($imagemCaptcha);
?>
I tried to pass the session variable like this:
<script>
jQuery(document).ready(function(){
$("#submit").on("click", function(event){
var nome = $("#nome").val();
var email = $("#email").val();
var uf = $("#uf").val();
var municipio = $("#municipio").val();
var telefone = $("#telefone").val();
var grupo = $("#grupo").val();
var assunto = $("#assunto").val();
var mensagem = $("#mensagem").val();
var captcha = $("#captcha").val();
var captcha_sessao = $("#SESSION['captcha']").val();
alert(captcha_sessao);
var emailFilter = /^.+@.+\..{2,}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\/\"\[\]]/;
if((emailFilter.test(email))||email.match(illegalChars)){
$.ajax({
type: "POST",
url: "processo.php",
dataType: "json",
beforeSend: function(){
$(".processo").html('Gravando contato...');
},
data: {'nome':nome,
'email':email,
'uf':uf,
'municipio':municipio,
'telefone':telefone,
'grupo':grupo,
'assunto':assunto,
'mensagem':mensagem,
'captcha':captcha,
'captcha_sessao':captcha_sessao},
success: function(json){
if(json.tipo == "0"){ // erro
$(".processo").html("<span class='erro'>"+json.msg+"</span>");
}else{ // sucesso
$(".processo").html("<span class='sucesso'>"+json.msg+"</span>");
cleanFields();
}
}
});
}else{
$(".processo").html("<p style='color:#f25824'>Por favor, informe um e-mail válido.</p>");
}
event.preventDefault();
});
});
</script>
The value of this variable that is the field entered with the generated captcha is sent to the process.php page:
var captcha = $("#captcha").val();
I do not know exactly how to proceed.