脚本宝典收集整理的这篇文章主要介绍了php – Zend_Form Captcha没有验证,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
//我在哪里打电话给我的表格
public function contactAction() { $this->view->form = new Forms_ContactForm(); }
//我的表格
class Forms_ContactForm extends TwITter_Form { public function init() { $this->setAction( 'email/email/contact' ); $this->setMethod('post'); $this->addElement('text','strFirstName',array( 'required' => true,'label' => 'Your First Name' ) ); $this->addElement('text','strLastName','label' => 'your Last Name' ) ); $this->addElement('text','strEmail',array( 'validators' => array( array('EmailAddress') ),'required' => true,'label' => 'Your Email' ) ); $this->addElement('textarea','strContent','label' => 'Your message' ) ); $this->addElement('captcha','captcha',array( 'label' => 'Please enter the 5 letters displayed below:','required' => true,'name' => 'captchaField','captcha' => 'image','captchaOptions' => array( 'captcha' => 'image','font'=> 'static/font/arial.ttf','imgDir'=>'static/img/captcha','imgurl'=> 'static/img/captcha/','wordLen' => 5,'fsize'=>20,'height'=>60,'width'=>200,'gCFreq'=>50,'expiration' => 300) )); $this->addElement('submit','submit',array('class' => 'Submit') ); } }
//以及我发送它的动作
public function contactAction() { if( $this->_request->isPost() ) { $objForm = new Forms_ContactForm(); if( $objForm->isValid($_POST) ) { $arrParams = $this->_request->getParams(); if( $arrParams['strFirstName'] && $arrParams['strLastName'] && $arrParams['strEmail'] && $arrParams['strContent'] ) { $this->_objEmail = new Zend_Mail(); $this->_objEmail ->setFrom( $arrParams['strEmail'] ); $this->_objEmail ->setSubject( 'C' ); $this->_objEmail ->setBodyHtML( 'Message from: '. $arrParams['strFirstName'] . ' ' . $arrParams['strLastName'] . '<br>eMail address: ' . $arrParams['strEmail'] . '<BR><BR>' . $arrParams['strContent'] ); $this->_objEmail ->addTo( 'mail@gmail.COM' ); $this->view->bolSent = $this->_objEmail->send(); } } else $this->view->form = $objForm; } }
似乎在我的contactAction中,它会生成一个新的验证码,这就是为什么它与我提交的代码完全匹配,但我不知道如何修复它.
感谢您的时间和帮助!
刚刚看到一些狡猾的东西:当我在接触动作中转储我的$_POST时,我的结果是:
array 'strFirstName' => string 'fghjfghj' (length=8) 'strLastName' => string 'ffffffff' (length=8) 'strEmail' => string 'fvhkbno@biu.fr' (length=14) 'strContent' => string 'fewfew' (length=6) 'captchaField' => string 'cebfe69ead38dba86a6b557dc8853b24' (length=32)
我刚刚输入的验证码甚至出现了,而我有验证码kay !! ??
编辑
再次感谢您的重播!
即使你的改变仍然没有,但我认为我错了.
这是我的验证码字段的html:
<div class="control-group"> <label class="control-label required" for="captchaField-input">Please enter the 5 letters displayed below:</label> <div class="controls"> <img width="200" height="60" src="static/img/captcha/ab2d15044a637338064b39cfd2675837.png" alt=""> <input tyPE="hidden" id="captchaField-id" value="ab2d15044a637338064b39cfd2675837" name="captchaField[id]"> <input type="text" value="" id="captchaField-input" name="captchaField[input]"> <input type="text" value="ab2d15044a637338064b39cfd2675837" id="captchaField" name="captchaField"> </div> </div>
当我查看我的params发送时,这是我得到的:
captchaField ab2d15044a637338064b39cfd2675837
captchaField [id] ab2d15044a637338064b39cfd2675837
captchaField [输入] 6af7u
似乎cptchaField重叠[id]和[输入]
我觉得我需要删除这个captchaField,但不知道到目前为止!
我可以用JS做到这一点,但必须有一个干净的方法来做到这一点!
再次编辑
我使用ajax提交表单,序列化.这可能是问题,看看有点不对劲.
编辑TER
它不是由ajax引起的.
如果我手动删除该行:
<input type="text" value="ab2d15044a637338064b39cfd2675837" id="captchaField" name="captchaField">
使用firebug,一切正常,验证码验证良好.现在的问题是如何正确删除这一行…
解
$captcha = new Zend_Form_Element_Captcha('captchaField',array('label' => "Please enter the 5 letters displayed below:",'required'=>true,'captcha' => array( 'captcha' => 'image','expiration' => 300 ) )); $this->addElement($captcha); $this->getElement('captchaField')->removeDecorator("viewhelper");
以上是脚本宝典为你收集整理的php – Zend_Form Captcha没有验证全部内容,希望文章能够帮你解决php – Zend_Form Captcha没有验证所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。