gpt4 book ai didi

php - Zend_Form 验证码未验证

转载 作者:可可西里 更新时间:2023-10-31 22:57:24 25 4
gpt4 key购买 nike

我已经阅读了很多关于此的帖子,但我无法解决我的问题。当我尝试验证我的 zend 表单验证码时,即使文本正确,它也总是失败。这是我的代码:

//我在哪里调用我的表单

 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', array(
'required' => true,
'label' => 'your Last Name' ) );

$this->addElement('text', 'strEmail', array( 'validators' => array(
array('EmailAddress') ),
'required' => true,
'label' => 'Your Email' ) );

$this->addElement('textarea', 'strContent', array(
'required' => true,
'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') );
}
}

//和我发送它的 Action

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>

当我查看我发送的参数时,这是我得到的:

验证码字段 ab2d15044a637338064b39cfd2675837验证码字段[id] ab2d15044a637338064b39cfd2675837验证码字段[输入] 6af7u

似乎 cptchaField 覆盖了 [id] 和 [input]

我觉得我需要删除这个 captchaField,但到目前为止还不知道该怎么做!

我可以用 JS 做到这一点,但必须有一种干净的方法来做到这一点!

再次编辑

我使用 ajax 提交表单,并进行序列化。这可能是问题所在,我来看看。

编辑之三

不是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',
'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($captcha);
$this->getElement('captchaField')->removeDecorator("viewhelper");

最佳答案

经过一番努力,这里是解决方案(我只需要删除装饰器)!

$captcha = new Zend_Form_Element_Captcha('captchaField',
array('label' => "Please enter the 5 letters displayed below:",
'required'=>true,
'captcha' => 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($captcha);
$this->getElement('captchaField')->removeDecorator("viewhelper");

感谢 Haroon 的帮助和抽出时间:)

关于php - Zend_Form 验证码未验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11063254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com