Nieuw lid |
|
Beste masters,
Ik ben een ajax formuliertje aan het maken maar loop net vast op de ajax validatie van een captcha. Indien de captcha niet correct is, wordt er 'false' gereturned, maar toch heb ik een submit. Hieronder een korte voorstelling van de code;
HTML
[code=default]
<form action="downloadCheck.php" onsubmit="return check();">
<fieldset>
<div id="captchaimage"><a href="<?php echo $_SERVER['PHP_SELF']; ?>" onclick="refreshimg();" title="Click to refresh image"><img src="images/image.php?<?php echo time(); ?>" width="132" height="46" alt="Captcha image" /></a></div>
<label for="captcha">Enter the characters as seen on the image above (case insensitive):</label>
<input type="text" maxlength="6" name="captcha" id="captcha" onblur="" />
<input type="submit" name="submit" id="submit" value="Check" />
</fieldset>
</form>
[code=default] <form action="downloadCheck.php" onsubmit="return check();"> <div id="captchaimage"><a href="<?php echo $_SERVER['PHP_SELF']; ?>" onclick="refreshimg();" title="Click to refresh image"> <img src="images/image.php?<?php echo time(); ?>" width="132" height="46" alt="Captcha image" /> </a></div> <label for="captcha">Enter the characters as seen on the image above (case insensitive): </label> <input type="text" maxlength="6" name="captcha" id="captcha" onblur="" /> <input type="submit" name="submit" id="submit" value="Check" />
Vervolgens de functie JAVASCRIPT check();
[code=default]
function check()
{
var submission = document.getElementById('captcha').value;
var url = 'process.php?captcha=' + submission;
//process.php post: 1 of 0; 1= captcha oke, 0 captcha niet oke
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')
{
return true;
}
if(showcheck == '0')
{
document.getElementById('captcha').style.background = '#ffbcbc';
return false;
}
}
}
[code=default] function check() { var submission = document.getElementById('captcha').value; var url = 'process.php?captcha=' + submission; //process.php post: 1 of 0; 1= captcha oke, 0 captcha niet oke 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') { return true; } if(showcheck == '0') { document.getElementById('captcha').style.background = '#ffbcbc'; return false; } } }
Iemand die mij kan helpen?
Alvast bedankt!
Yannick
|