J'ai lu quelques articles à ce sujet, mais je n'ai pas été capable de résoudre mon problème. Lorsque j'essaie de valider mon captcha zend form, il échoue toujours même avec le texte correct. Voici mon code:Zend_Form Captcha ne valide pas
// où j'appelle ma forme
public function contactAction()
{
$this->view->form = new Forms_ContactForm();
}
// ma forme
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'));
}
}
// et mon action pour l'envoyer
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('[email protected]');
$this->view->bolSent = $this->_objEmail->send();
}
}
else
$this->view->form = $objForm;
}
}
Il semble que dans mon contactAction, il génère un nouveau code captcha, c'est pourquoi il ne correspond pas avec celui que je submi mais je n'ai aucune idée de comment y remédier.
Nous vous remercions de votre temps et de votre aide !!
Je viens de voir quelque chose de louche: quand je largue mon _POST $ en action de contact ici est mon résultat:
array
'strFirstName' => string 'fghjfghj' (length=8)
'strLastName' => string 'ffffffff' (length=8)
'strEmail' => string '[email protected]' (length=14)
'strContent' => string 'fewfew' (length=6)
'captchaField' => string 'cebfe69ead38dba86a6b557dc8853b24' (length=32)
Le captcha Je viens entré dosent même apparaître et à la place je le captcha kay !! ??
EDIT
merci encore pour votre replay !!! Toujours pas là, même avec vos changements, mais je pense que j'ai eu quoi de mal. Voici mon html pour le champ captcha:
<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>
Quand je regarde mes params envoyé, voici ce que je suis:
captchaField ab2d15044a637338064b39cfd2675837 captchaField [id] ab2d15044a637338064b39cfd2675837 captchaField [entrée] 6af7u
Il semble que cptchaField overwright [id] et [entrée]
Je sens que je dois enlever ce captchaField mais je ne sais pas comment jusqu'ici!
Je pourrais le faire avec JS mais il doit y avoir un moyen propre de le faire!
EDIT DE NOUVEAU
Im en utilisant ajax pour soumettre le formulaire, avec serialize. Cela pourrait être le problème, mal jeter un oeil.
EDIT TER
Il n'est pas causée par ajax. Si je supprimer manuellement la ligne:
<input type="text" value="ab2d15044a637338064b39cfd2675837" id="captchaField" name="captchaField">
avec Firebug, tout est normal et le captcha valide bien. Maintenant, la question est de savoir comment supprimer cette ligne correctement ...
SOLUTION
Après avoir lutté beaucoup, voici la solution (enlever décorateur)!
$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");
comment est votre élément Captcha affiché dans votre fichier de vue? – Haroon
Est-ce que le code dans le fichier de vue ou est-il la source HTML de la page? – Haroon
mon code de vue est tout simplement echo $ this-> forme Ceci est le code source, construit automatiquement par zend – mokk