PHP Ajax Captcha(Securimage) issue
i have a little problem with captcha validation using php and ajax. this is the php validation:
if(trim($code) == '') {
$error_captcha = '<p class="error">some empty error....</p>';
$errorc = 'error';
$error = $erdiv;
} else if (trim($code) != ''){
require_once ('securimage.php');
$captcha = new Securimage();
$valid = $captcha->check($code);
if ($valid == false) {
echo '<p class="error">some captcha incorrect error...</p>';
$error_captcha .= '<p class="error"></p>';
}
}
this is my form:
<form class="wufoo leftLabel page" action="javascript:send_action('register.php',3)">
<div class="info">
<h2>פזור - טופס רישום</h2>
<?php echo $error; ?>
</div>
<ul>
<li class="right <?php echo $erroru; ?>">
<div class="col">
<input type="text" class="field text large" id="user_register" value="<?php echo $username; ?>" maxlength="255" />
<?php echo $error_user; ?>
</div>
<label class="desc">
<span class="req">*</span>
<?php small('שם משתמש'); ?>
</label>
<p class="instruct"><small>שם המשתמש</small></p>
</li>
<li class="right <?php echo $errorp; ?>">
<div class="col">
<input type="password" class="field text large" id="pass_register" value="<?php echo $pass; ?>" maxlength="255" />
<?php echo $error_pass; ?>
</div>
<label class="desc">
<span class="req">*</span>
<?php small('סיסמא'); ?>
</label>
<p class="instruct"><small>נא הזן את סיסמתך</small></p>
</li>
<li class="right <?php echo $errorp.''.$errorpv; ?>">
<div class="col">
<input type="password" class="field text large" id="pass_val_register" value="<?php echo $pass_val; ?>" maxlength="255" />
<?php echo $error_pass_val.''.$error_pass; ?>
</div>
<label class="desc">
<span class="req">*</span>
<?php small('אימות סיסמא'); ?>
</label>
<p class="instruct"><small>נא הזן את סיסמתך שנית</small></p>
</li>
<li class="right <?php echo $errore; ?>">
<div class="col">
<input type="text" class="field text large" id="email_register" value="<?php echo $email; ?>" maxlength="255" />
<?php echo $error_email; ?>
</div>
<label class="desc">
<span class="req">*</span>
<?php small('כתובת דוא"ל'); ?>
</label>
<p class="instruct"><small>נא הקפד להזין כתובת דוא"ל חוקית על מנת שתוכל להפעיל את חשבונך</small></p>
</li>
<li class="right captcha"></li>
<li class="right <?php echo $errorc; ?>">
<div class="col">
<input type="text" class="field text large" id="captcha_register" maxlength="255" 开发者_Python百科/>
<p><img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></p>
<?php echo $error_captcha; ?>
</div>
<label class="desc">
<span class="req">*</span>
<?php small('קוד אבטחה'); ?>
</label>
<p class="instruct"><small>נא הזן את קוד האבטחה כפי שמופיע בתמונה</small></p>
</li>
<li class="buttons ">
<input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="שלח" />
</li>
</ul>
</form>
(that's thbrew there) The problem is that the variable $eror_captcha isn't set at all when entering a wrong string.
JQman, there are a few things about your code that will make it difficult to help you troubleshoot. The first is not knowing how the valid captcha process works. Meaning, we cannot see what $valid = $captcha->check($code); actually does. But assuming your code will actually set a reference correctly to the valid captch code and that it will return 'false' when the code the person enters does not match, here are a few things to check:
1- When I load this into a test environment, I cannot get the form to show. When I remove all of the lines, I get a complete form and the error message shows. Try removing the small() lines and see if it will work. If so, then there is something wrong with the small() function.
2- I notice this is running on wufoo. I am not extremely familiar with their service but I am aware of it. They may do something to cause the code to halt on warnings/errors. That being said, I notice that if someone enters an invalid code, you append $error_captcha like so: $error_captcha .= '
'; ... however, $error_captcha is not previously set in the code you show. This will cause a warning in the log. You may want to consider removing the .= and making it =.Other than that, I do not see anything else that would lead to changing the results you are currently getting.
精彩评论