<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi all. I have a custom form, and I need to send it via ajax. I know that exist ['#ajax'] so &nbsp;this is my form:<div><br></div><div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form = array();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['name'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#type'=&gt; 'textfield',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#size' =&gt; 30,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#title'=&gt; 'Nome',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#weight' =&gt; "float up"</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['email'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#type'=&gt; 'textfield',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#size' =&gt; 30,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#title'=&gt; 'Email',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['phone'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#type'=&gt; 'textfield',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#size' =&gt; 30,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#title'=&gt; 'Telefono',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['msg'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#type'=&gt; 'textarea',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#size' =&gt; 30,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#rows' =&gt; 3,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#title'=&gt; 'msg',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['my_captcha_element'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;'#type' =&gt; 'captcha',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;'#captcha_type' =&gt; 'captcha/Math',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);</div><div>&nbsp;&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['invia'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#type'=&gt; 'submit',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#value' =&gt; 'Invia',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#weight' =&gt; 40,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#ajax' =&gt; array(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>'callback' =&gt; 'xblock_form_contatto_ad_form_submit',</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>'wrapper' =&gt; 'form_submit',</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>),</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>$form['markup'] = array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#prefix' =&gt; '&lt;div id="form_submit"&gt;',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#suffix' =&gt; '&lt;/div&gt;',</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>'#markup' =&gt; '',</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div></div><div><br></div><div>This is my callback function:&nbsp;</div><div><div>function xblock_form_contatto_ad_form_submit($form, $fs) {</div></div><div>&nbsp;&nbsp;$errors = form_get_errors();</div><div>&nbsp; &nbsp; if ($errors) {</div><div>&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>$out ="&lt;span style='color: red;'&gt;";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;foreach ($errors as $k =&gt; $v) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> &nbsp; &nbsp;$out .= $v."&lt;br&gt;";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;$out .="&lt;/span&gt;";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;return $out;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; $body = theme('xblock_form_contatto_ad_form',array('data' =&gt; $fs['values']));</div><div>&nbsp; mail("<a href="mailto:michel@ziobuddalabs.it">michel@ziobuddalabs.it</a>","Contatto da form",$body);</div><div>&nbsp; return "&lt;span style='color: green;'&gt;Invio effettuato&lt;/span&gt;";</div><div>}</div><div><br></div><div>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:</div><div><br></div><ol class="properties properties-tree monospace" tabindex="0" style="box-sizing: border-box; outline-style: none; outline-width: initial; outline-color: initial; font-size: 11px !important; font-family: Menlo, monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 6px; padding-bottom: 2px; padding-left: 16px; list-style-type: none; list-style-position: initial; list-style-image: initial; min-height: 18px; display: block; -webkit-text-size-adjust: none; "><li title="" class="parent" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><font class="Apple-style-span" color="#881391"><span class="Apple-style-span" style="font-family: 'Lucida Grande', sans-serif; font-size: 10px; color: rgb(0, 0, 0); white-space: normal; "><ol class="properties properties-tree monospace" tabindex="0" style="box-sizing: border-box; font-size: 11px !important; font-family: Menlo, monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 6px; padding-bottom: 2px; padding-left: 16px; list-style-type: none; list-style-position: initial; list-style-image: initial; min-height: 18px; display: block; "><li title="" class="parent" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">0</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; ">{command:settings, settings:{basePath:/, pathPrefix:,…}, merge:true}</span></li><li title="" class="parent expanded" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">1</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; ">{command:insert, method:null, selector:null,…}</span></li><ol class="children expanded" style="box-sizing: border-box; display: block; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; -webkit-padding-start: 12px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">command</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre; ">"insert"</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">data</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre; ">"&lt;span style='color: red;'&gt;The answer you entered for the CAPTCHA was not correct.&lt;br&gt;&lt;/span&gt;"</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">method</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-null" style="box-sizing: border-box; color: rgb(128, 128, 128); ">null</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">selector</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-null" style="box-sizing: border-box; color: rgb(128, 128, 128); ">null</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">settings</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-null" style="box-sizing: border-box; color: rgb(128, 128, 128); ">null</span></li></ol><li title="" class="parent expanded" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">2</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; ">{command:insert, method:prepend, selector:null,…}</span></li><ol class="children expanded" style="box-sizing: border-box; display: block; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; -webkit-padding-start: 12px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">command</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre; ">"insert"</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">data</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre; ">"&lt;div class="messages error"&gt;↵&lt;h2 class="element-invisible"&gt;Error message&lt;/h2&gt;↵ &lt;ul&gt;↵  &lt;li&gt;CAPTCHA session reuse attack detected.&lt;/li&gt;↵  &lt;li&gt;The answer you entered for the CAPTCHA was not correct.&lt;/li&gt;↵ &lt;/ul&gt;↵&lt;/div&gt;↵"</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">method</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre; ">"prepend"</span></li><li title="" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">selector</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-null" style="box-sizing: border-box; color: rgb(128, 128, 128); ">null</span></li><li title="" class="selected" style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow-x: hidden; overflow-y: hidden; -webkit-user-select: text; cursor: auto; "><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145); ">settings</span><span class="separator" style="box-sizing: border-box; ">:&nbsp;</span><span class="value console-formatted-null" style="box-sizing: border-box; color: rgb(128, 128, 128); ">null</span></li></ol></ol></span><div><br></div><div><br></div></font></li></ol><div>"CAPTCHA session reuse attack detected" ???</div><div><br></div><div><br></div><div>M.</div><div apple-content-edited="true"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">--<br>Michel 'ZioBudda' Morelli&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:michel@ziobuddalabs.it">michel@ziobuddalabs.it</a><br>Sviluppo applicazioni CMS DRUPAL e web dinamiche&nbsp;(LAMP+Ajax)<br>0200619074 - 3939890025 (mobile)-- &nbsp;Fax: +39-0291390660<br><a href="http://www.ziobuddalabs.it">http://www.ziobuddalabs.it</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Skype: zio_budda</div>
</div>

<br></div></body></html>