Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
E ae galera, tudo bem com vocês? ^^
Desculpe pelo longo post.
Bom, é o seguinte. Tenho um script de formulário que é o seguinte:
O FORM tem o action="" e no botão de enviar, tem a chamada para o JS, ou seja, onclick="sendemail();".
<script type='text/javascript' src='./contact/contact.js'></script>
<script type='text/javascript' src='./scripts/validaform.js'></script>
<div id="contactarea">
<form name="contactform" id="contactform" action="">
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="50%" align="right" valign="top"><?php echo $texto['contact_name']; ?>:</td>
<td width="50%" align="left" valign="middle"><input type="text" name="name" id="inputbox"></td>
</tr>
<tr>
<td align="right" valign="top">E-mail:</td>
<td align="left" valign="middle"><input type="text" name="email" id="inputbox"></td>
</tr>
<tr>
<td valign="middle" align="center" colspan="2"> <div id="errormsg"><?php echo $texto['contact_email_info']; ?></div>
</td>
</tr>
<tr>
<td align="right" valign="top"><?php echo $texto['contact_sub']; ?>:</td>
<td align="left" valign="middle"><input type="text" name="subject" id="inputbox"></td>
</tr>
<tr>
<td align="right" valign="top"><?php echo $texto['contact_msg']; ?>:</td>
<td align="left" valign="middle"><textarea name="msg" rows="10" id="textarea"></textarea></td>
</tr>
<tr>
<td align="right" valign="top"> </td>
<td align="left" valign="middle">
<input type="button" value="<?php echo $texto['contact_send']; ?>" name="send" id="submitbutton" onclick='sendemail();'></td>
</tr>
</table>
</form>
</div>
Essa chamada nos leva ao JavaScript, que é o seguinte:
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sendemail() {
var msg = document.contactform.msg.value;
var name = document.contactform.name.value;
var email = document.contactform.email.value;
var subject = document.contactform.subject.value;
document.contactform.send.disabled=true;
document.contactform.send.value='Enviando|Sending';
http.open('get', 'contact/contact.php?msg='+msg+'&name='+name+'&subject='+subject+'&email='+email+'&action=send');
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
Ok. Após isso, ele envia as infos para o contact.php. Segue:
<?php
include "../languages/setidioma.php";
if(!isset($_GET['action']))
{
die("You must not access this page directly!"); //Just to stop people from visiting contact.php normally
}
/ Now lets trim up the input before sending it /
$name = trim($_GET['name']); //The senders name
$email = trim($_GET['email']); //The senders email address
$subject = trim($_GET['subject']); //The senders subject
$message = trim($_GET['msg']); //The senders message
if ($name=="" || $email=="" || $subject=="" || $message=="" )
{
echo "contactarea|". $texto['contact_error']."<br /><a href=\"java script:window.location.reload( false );\">".$texto['back']."<a/>";
}
else {
//do email format validation
if(!eregi('^([._a-z0-9-]+[._a-z0-9-])@(([a-z0-9-]+\.)([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
echo "contactarea|".$texto['invalid_email']."<br /><a href=\"java script:window.location.reload( false );\">".$texto['back']."<a/>";;
exit;
}
$to = "ddl@raphaelddl.com"; //This is the email address you want to send the email to
$headers = "From: $name <$email>\n";
$subjects = $subject .'____RaphaelDDL.com Contact';
mail($to, $subjects, $message, $headers);
echo "contactarea|<center><img src=\"../images/contact/mail.png\" style=\"width:384px;height:384px;\"><br />".$texto['contact_thx']."</center>";
}
//now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
?>O include no começo e os $texto são coisas extras, pois o site é multi-lingua..
OK, tudo isso funciona de boa, se tiver algo errado ele aparece falando que tá errado e talz.
Perfeito o script :D
Agora eu queria é adicionar um CAPTCHA Image nele.
Achei na internet um tipo de captcha que Chama Freecap.
Aqui você pode baixá-lo.
http://www.puremango.co.uk/cm_php_captcha_script_113.php
Bom, peguei o arquivo de exemplo (freecap_wrap.php) e catei os códigos.
Aí ficou assim meu contact.
<?php
session_start();
if(!empty($_SESSION['freecap_word_hash']) && !empty($_POST['word']))
{
// all freeCap words are lowercase.
// font #4 looks uppercase, but trust me, it's not...
if($_SESSION['hash_func'](strtolower($_POST['word']))==$_SESSION['freecap_word_hash'])
{
// reset freeCap session vars
// cannot stress enough how important it is to do this
// defeats re-use of known image with spoofed session id
$_SESSION['freecap_attempts'] = 0;
$_SESSION['freecap_word_hash'] = false;
// now process form
// now go somewhere else
// header("Location: somewhere.php");
$word_ok = "yes";
} else {
$word_ok = "no";
}
} else {
$word_ok = false;
}
?>
<script language="javascript">
<!--
function new_freecap()
{
// loads new freeCap image
if(document.getElementById)
{
// extract image name from image source (i.e. cut off ?randomness)
thesrc = document.getElementById("freecap").src;
thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
// add ?(random) to prevent browser/isp caching
document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
} else {
alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
}
}
//-->
</script>
<script type='text/javascript' src='./contact/contact.js'></script>
<script type='text/javascript' src='./scripts/validaform.js'></script>
<div id="contactarea">
<form name="contactform" id="contactform" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="50%" align="right" valign="top"><?php echo $texto['contact_name']; ?>:</td>
<td width="50%" align="left" valign="middle"><input type="text" name="name" id="inputbox"></td>
</tr>
<tr>
<td align="right" valign="top">E-mail:</td>
<td align="left" valign="middle"><input type="text" name="email" id="inputbox"></td>
</tr>
<tr>
<td valign="middle" align="center" colspan="2"> <div id="errormsg"><?php echo $texto['contact_email_info']; ?></div>
</td>
</tr>
<tr>
<td align="right" valign="top"><?php echo $texto['contact_sub']; ?>:</td>
<td align="left" valign="middle"><input type="text" name="subject" id="inputbox"></td>
</tr>
<tr>
<td align="right" valign="top"><?php echo $texto['contact_msg']; ?>:</td>
<td align="left" valign="middle"><textarea name="msg" rows="10" id="textarea"></textarea></td>
</tr>
<!-- CAPTCHA AQUI -->
<tr><td colspan="2" align="center" Valign="middle"><img src="contact/freecap.php" id="freecap"></td></tr>
<tr><td colspan="2" align="center" valign="top">If you can't read the word, <a href="#" onClick="this.blur();new_freecap();return false;">click here</a></td></tr>
<tr>
<td align="right" valign="top">word above:</td>
<td align="left" valign="middle"><input type="text" name="word"></td></tr>
<!-- CAPTCHA AQUI -->
<tr>
<td align="right" valign="top"> </td>
<td align="left" valign="middle">
<input type="button" value="<?php echo $texto['contact_send']; ?>" name="send" id="submitbutton"></td>
</tr>
</table>
<div id="errormsg"><?
if($word_ok!==false)
{
if($word_ok=="yes")
{
echo "you got the word correct, rock on.<br />";
} else {
echo "sorry, that's not the right word, try again.<br />";
}
}
?></div>
</form>
</div>
Mas nao funciona... De jeitu nenhum, ja mudei altas coisas e nada...
Alguém saberia se há como fazer essa integração?
Desculpe novamente pelo longo post.
Agradeço desde já
Raphael DDL
Carregando comentários...