Jump to content

AJAX captcha help


exhaler

Recommended Posts

hi,

i'm currently using ajax to display my captcha. i found it on the internet

http://psyrens.com/captcha/

but for some reason i can't process the form when i press the submit button and typed in the correct captcha

i've tried contacting the author but still no reply

<script type="text/javascript" src="captcha.js"></script>
<form method="post" action="readfeatured.php?id=<?php echo $id; ?>" name="addcomment" id="addcomment" class="cmxform" onsubmit="check(); return false;"> 
<table border="0" cellpadding="0" cellspacing="3" width="1%" height="1%">
<tr>
	<td valign="top" align="left">
		<font color="#B9A49B" face="Arial, Helvetica, sans-serif" style="font-size: 8pt">
			Name:
		</font>
	</td>


<tr>
	<td valign="top" align="left" style="width: 100px">

	</td>

	<td valign="top" align="left" colspan="2"> 
		 <font color="#B9A49B" face="Arial, Helvetica, sans-serif" style="font-size: 8pt;">
		 	Enter the characters as seen on the image (case insensitive):
		 </font>
		 <div id="captchaimage">
		 	<a href="<?php echo $_SERVER['PHP_SELF']; ?>" onclick="refreshimg(); return false;" title="Click to refresh image">
		 		<img src="images/image.jpg?<?php echo time(); ?>" width="132" height="46" alt="Captcha image" border="0" />
		 	</a>
		 </div>

		 <input type="text" maxlength="6" name="captcha" id="captcha" />
	</td>
</tr>

<tr>
	<td valign="top" align="center" colspan="2">
		<input type="submit" value="Submit" name="submit" style="font-size: 8pt; font-family: Arial, Helvetica, sans-serif" />
	</td>
</tr>
</table><!--END of Table5 -->
</form>

 

code for captcha.js

// CREATING THE REQUEST

function createRequestObject()
{
try
{
	xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject

("Microsoft.XMLHTTP");
}
catch(e)
{
	alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
}
return xmlhttp;
}

var http = createRequestObject();
var sess = createRequestObject();

// IMAGE REFRESHING

function refreshimg()
{
var url = 'image_req.php';
dorefresh(url, displayimg);
}

function dorefresh(url, callback)
{
sess.open('POST', 'newsession.php', true);
sess.send(null);
http.open('POST', url, true);
http.onreadystatechange = displayimg;
http.send(null);
}

function displayimg()
{
if(http.readyState == 4)
{
	var showimage = http.responseText;
	document.getElementById('captchaimage').innerHTML = showimage;
}
}

// SUBMISSION

function check()
{
var submission = document.getElementById('captcha').value;
var url = 'process.php?captcha=' + submission;
docheck(url, displaycheck);
}

function docheck(url, callback)
{
http.open('GET', url, true);
http.onreadystatechange = displaycheck;
http.send(null);
}

function displaycheck()
{
if(http.readyState == 4)
{
	var showcheck = http.responseText;
	if(showcheck == '1')
	{
		document.getElementById('captcha').style.border = '1px solid #49c24f';
		document.getElementById('captcha').style.background = '#bcffbf';

	}
	if(showcheck == '0')
	{
		document.getElementById('captcha').style.border = '1px solid #c24949';
		document.getElementById('captcha').style.background = '#ffbcbc';
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/152631-ajax-captcha-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.