Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/12/2009, 14:35
SeNdEr2003
 
Fecha de Ingreso: agosto-2003
Mensajes: 906
Antigüedad: 20 años, 8 meses
Puntos: 3
Controlar captcha a medida que escribe

Buenas

Estoy tratando de controlar un codigo captcha mientras escribe que vaya diciendo, el tema es que no se bien como obtener el valor si esta bien ingresado o no...aqui dejo lo que estoy haciendo:

Código PHP:
    <!--<div class="yui-u first">
                 <label for="email">Email: <input type="text" id="edit-subject" name="subject" class="form_t1" /><br /><span class="coment_mail">no se mostrará</span></label>
    </div> -->
<style type="text/css">
body { font-family: Arial; font-size: 12px; padding: 20px; }
#result { border: 1px solid green; width: 250px; margin: 0 0 5px 0; padding: 2px 20px; font-weight: bold; }
#change-image { font-size: 0.8em; }
#form{border: 1px solid rgb(148, 163, 196);margin: 0px 0px 15px;width:290px;}
form h3{background: rgb(236, 239, 245);display:block;margin: 0px 0px 0px;padding: 5px 10px;}
</style>
<?php
/** Validate captcha */
if (!empty($_REQUEST['captcha'])) {

    if (empty(
$_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
        
$captcha_message "Captcha incorrecto"$style "background-color: #FF606C";
    } else {
        
$captcha_message "Captcha correcto!"$style "background-color: #CCFF99";
    }
    
$request_captcha htmlspecialchars($_REQUEST['captcha']);

    echo <<<HTML
        <div id="result" style="$style">
        <h3>$captcha_message</h3>
        </div>
HTML;
        
    unset(
$_SESSION['captcha']);
}
?>
<script language = "javascript">
function createRequestObject(){
       var peticion;
       var browser = navigator.appName;
       if(browser == "Microsoft Internet Explorer"){
          peticion = new ActiveXObject("Microsoft.XMLHTTP");
}else{
      peticion = new XMLHttpRequest();
}
return peticion;
}
var http = new Array();
function ObtDatos(url){
      var act = new Date();
      http[act] = createRequestObject();
      http[act].open('get', url);
      http[act].onreadystatechange = function() {
    if (http[act].readyState == 4) {
        if (http[act].status == 200 || http[act].status == 304) {
        var texto
        texto = http[act].responseText
        var DivDestino = document.getElementById("DivDestino");
        DivDestino.innerHTML = texto; 
       }
    }
}
http[act].send(null);
}
function compUsuario(Tecla) {
       Tecla = (Tecla) ? Tecla: window.event;
       input = (Tecla.target) ? Tecla.target : 
       Tecla.srcElement;
       if (Tecla.type == "keyup") {
           var DivDestino = document.getElementById("DivDestino");
           DivDestino.innerHTML = "<div></div>";
           if (input.value) {
              ObtDatos("/themes/theme/comment-theme-form.tpl.php?q=" + input.value);
              } 
       }
}
</script>
<form id="form" method="GET">
<div style="padding:20px">
<img src="/themes/theme/captcha.php" id="captcha" /><br/>
<!-- CHANGE TEXT LINK -->
<a href="#" onclick="document.getElementById('captcha').src='/themes/theme/captcha.php?'+Math.random();" id="change-image">Recargar Captcha.</a><br/><br/>
<div style="margin-top:8px;"><span style="font-size:12px;">Ingrese el codigo:</span><br><input type="text" name="code" onkeyup="compUsuario(event)" class="form_t2" style="width:142px;"></div>
</div>
<div class="yui-u first" class="form_t2">
    <label for="comentario" class="form_t2"><?php print $form['_author']['#value']; ?> dice:<textarea rows="6" cols="45" id="edit-comment" name="comment" class="form_t2"></textarea></label>
        <div id = "DivDestino"></div>
        <div class="boton"><input type="submit" class="boton" name="op" id="edit-submit" value="<?php print t($form['submit']['#value']); ?>"  /></div>
    </div>
    <input type="hidden" name="form_token" id="<?php print $form['form_token']['#id']; ?>" value="<?php print $form['form_token']['#value']; ?>"  />
    <input type="hidden" name="form_id" id="edit-comment-form" value="<?php print $form['form_id']['#value']; ?>"  />
</form>
</div>
Me carga bien el codigo captcha pero como hago para saber si va escribiendo bien?, porque siempre usa un action para controlar pero no deseo hacer eso...