Captcha in form personalizzato

1 contenuto / 0 new
Captcha in form personalizzato

Ciao a tutti, in un modulo peronalizzato di prenotazioni online vorrei mettere la funzionalità Captcha, che conosco bene in un form php, ma che in drupal non funziona. Il codice, inserito un un hook form, è questo:

<?php
   
if (isset($_SESSION['captchaText'])) {
     
$captchaText = $_SESSION['captchaText'];
     
$path_captcha = drupal_get_path("module", "prenota") . "/captcha.php?captchaText=" . $_SESSION['captchaText'];
      unset(
$_SESSION['captchaText']);
    } else {
     
$captchaText = substr(md5(uniqid('')),-5,5);
     
$_SESSION['captchaText'] = $captchaText;
     
$path_captcha = drupal_get_path("module", "prenota") . "/captcha.php?captchaText=" . $captchaText;
    }
$form['info_privacy_fileds']['txt_captcha'] = array(
     
'#type' => 'item',
     
'#title' => t('Inserisci il codice antispam-antihacker'),
     
'#description' => t('Questa e una protezione Antispam/Antihacker'),
     
'#maxlength' => 6,
     
'#size' => 18,
     
'#value' => '',
     
'#required' => TRUE,
     
'#prefix' => '<div>',
     
'#suffix' => '<img src="'.$path_captcha.'" alt="Protezione per convalidare i campi del modulo prima di inviare e-mail" name="captcha" width="233" height="49" id="captcha" /></div>',
     
'#attributes' => array('id' => 'txt_captcha'),
    );
   
$form['info_privacy_fileds']['txt_captcha_hidden'] = array('#type' => 'hidden', '#size' => 18, '#value' => $captchaText);
   
$form['info_privacy_fileds']['txt_captcha_insert'] = array(
     
'#type' => 'textfield',
     
'#size' => 18,
     
'#maxlength' => 5,
     
'#default_value' => variable_get('txt_captcha_insert', ''),
    );
 
?>

Il codice, inserito un un hook validate, è questo:
<?php
 
if (empty($form_state['values']['txt_captcha_insert'])) {
   
form_set_error('txt_captcha_insert', t('Completare il codice di sicurezza! Nota: non fa differenza tra maiuscole minuscole'));
  }
  if (!empty(
$form_state['values']['txt_captcha_insert'])) {
    if (
$_SESSION['captchaText'] != $form_state['values']['txt_captcha_insert']){
     
form_set_error('captcha_code_file', t('Il Codice di sicurezza non corrisponde: riprovare'));
    }
  }
 
?>

Dopo il Submit mi dà sempre Il Codice di sicurezza non corrisponde: riprovare Cosa posso fare?