Hi all. I have a custom form, and I need to send it via ajax. I know that exist ['#ajax'] so this is my form:
$form = array(); $form['name'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Nome', '#weight' => "float up"
); $form['email'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Email', ); $form['phone'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Telefono', ); $form['msg'] = array( '#type'=> 'textarea', '#size' => 30, '#rows' => 3, '#title'=> 'msg', ); $form['my_captcha_element'] = array( '#type' => 'captcha', '#captcha_type' => 'captcha/Math', );
$form['invia'] = array( '#type'=> 'submit', '#value' => 'Invia', '#weight' => 40, '#ajax' => array( 'callback' => 'xblock_form_contatto_ad_form_submit', 'wrapper' => 'form_submit', ), ); $form['markup'] = array( '#prefix' => '<div id="form_submit">', '#suffix' => '</div>', '#markup' => '', );
This is my callback function: function xblock_form_contatto_ad_form_submit($form, $fs) { $errors = form_get_errors(); if ($errors) { $out ="<span style='color: red;'>"; foreach ($errors as $k => $v) { $out .= $v."<br>"; } $out .="</span>"; return $out; }
$body = theme('xblock_form_contatto_ad_form',array('data' => $fs['values'])); mail("michel@ziobuddalabs.it","Contatto da form",$body); return "<span style='color: green;'>Invio effettuato</span>"; }
My problem is the form validation: I have a captcha and I do not insert nothing so captcha validate return an error, and I can see it in the json "command" result, but when I reinsert the captcha with correct "entry" I get this:
0: {command:settings, settings:{basePath:/, pathPrefix:,…}, merge:true} 1: {command:insert, method:null, selector:null,…} command: "insert" data: "<span style='color: red;'>The answer you entered for the CAPTCHA was not correct.<br></span>" method: null selector: null settings: null 2: {command:insert, method:prepend, selector:null,…} command: "insert" data: "<div class="messages error">↵<h2 class="element-invisible">Error message</h2>↵ <ul>↵ <li>CAPTCHA session reuse attack detected.</li>↵ <li>The answer you entered for the CAPTCHA was not correct.</li>↵ </ul>↵</div>↵" method: "prepend" selector: null settings: null
"CAPTCHA session reuse attack detected" ???
M. -- Michel 'ZioBudda' Morelli michel@ziobuddalabs.it Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax) 0200619074 - 3939890025 (mobile)-- Fax: +39-0291390660 http://www.ziobuddalabs.it Skype: zio_budda
SOLVED with a patch that I have found in an issue.
M. Il giorno 05/giu/2012, alle ore 18:01, D. Michel Morelli ha scritto:
Hi all. I have a custom form, and I need to send it via ajax. I know that exist ['#ajax'] so this is my form:
$form = array(); $form['name'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Nome', '#weight' => "float up"
); $form['email'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Email', ); $form['phone'] = array( '#type'=> 'textfield', '#size' => 30, '#title'=> 'Telefono', ); $form['msg'] = array( '#type'=> 'textarea', '#size' => 30, '#rows' => 3, '#title'=> 'msg', );
$form['my_captcha_element'] = array( '#type' => 'captcha', '#captcha_type' => 'captcha/Math', );
$form['invia'] = array( '#type'=> 'submit', '#value' => 'Invia', '#weight' => 40, '#ajax' => array( 'callback' => 'xblock_form_contatto_ad_form_submit', 'wrapper' => 'form_submit', ), );
$form['markup'] = array( '#prefix' => '<div id="form_submit">', '#suffix' => '</div>', '#markup' => '', );
This is my callback function: function xblock_form_contatto_ad_form_submit($form, $fs) { $errors = form_get_errors(); if ($errors) { $out ="<span style='color: red;'>"; foreach ($errors as $k => $v) { $out .= $v."<br>"; } $out .="</span>"; return $out; }
$body = theme('xblock_form_contatto_ad_form',array('data' => $fs['values'])); mail("michel@ziobuddalabs.it","Contatto da form",$body); return "<span style='color: green;'>Invio effettuato</span>"; }
My problem is the form validation: I have a captcha and I do not insert nothing so captcha validate return an error, and I can see it in the json "command" result, but when I reinsert the captcha with correct "entry" I get this:
0: {command:settings, settings:{basePath:/, pathPrefix:,…}, merge:true} 1: {command:insert, method:null, selector:null,…} command: "insert" data: "<span style='color: red;'>The answer you entered for the CAPTCHA was not correct.<br></span>" method: null selector: null settings: null 2: {command:insert, method:prepend, selector:null,…} command: "insert" data: "<div class="messages error">↵<h2 class="element-invisible">Error message</h2>↵ <ul>↵ <li>CAPTCHA session reuse attack detected.</li>↵ <li>The answer you entered for the CAPTCHA was not correct.</li>↵ </ul>↵</div>↵" method: "prepend" selector: null settings: null
"CAPTCHA session reuse attack detected" ???
M.
Michel 'ZioBudda' Morelli michel@ziobuddalabs.it Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax) 0200619074 - 3939890025 (mobile)-- Fax: +39-0291390660 http://www.ziobuddalabs.it Skype: zio_budda
-- Michel 'ZioBudda' Morelli michel@ziobuddalabs.it Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax) 0200619074 - 3939890025 (mobile)-- Fax: +39-0291390660 http://www.ziobuddalabs.it Skype: zio_budda