2

I have a simple contact form.When I submit form error messages not display.Pls help me

class Users_Form_ContactForm extends Zend_Form{
    public function init(){
        $this->setName('contact');

        $user_name = new Zend_Form_Element_Text('name');
        $user_name->setLabel($this->getView()->translate('Ismingiz:'));
        $user_name->setRequired(true)
                ->addValidator('alnum')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setAttrib('class', 'input margin_top_10');

        $email_validate = new Zend_Validate_EmailAddress();
        $email_validate->setMessages(array(
                                          Zend_Validate_EmailAddress::INVALID => "1. Invalid type given, value should be a string",
                                          Zend_Validate_EmailAddress::INVALID_FORMAT => "2. '%value%' is no valid email address in the basic format local-part@hostname",
                                          Zend_Validate_EmailAddress::INVALID_HOSTNAME => "3. '%hostname%' is no valid hostname for email address '%value%'",
                                          Zend_Validate_EmailAddress::INVALID_MX_RECORD => "4. '%hostname%' does not appear to have a valid MX record for the email address '%value%'",
                                          Zend_Validate_EmailAddress::INVALID_SEGMENT => "5. '%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.",
                                          Zend_Validate_EmailAddress::DOT_ATOM => "6. '%localPart%' can not be matched against dot-atom format",
                                          Zend_Validate_EmailAddress::QUOTED_STRING => "7. '%localPart%' can not be matched against quoted-string format",
                                          Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "8. '%localPart%' is no valid local part for email address '%value%'",
                                          Zend_Validate_EmailAddress::LENGTH_EXCEEDED => "9. '%value%' exceeds the allowed length",
                                     ));

        $email = new Zend_Form_Element_Text("email");
        $email->setLabel($this->getView()->translate("Email manzilingiz:"))
                ->setRequired(true)
                ->addValidator($email_validate)
                ->addFilter('StringTrim')
                ->setAttrib('class', 'input margin_top_10')
                ->addFilter('StringToLower');

        $captcha = new Zend_Form_Element_Captcha('captcha', array(
                                                                 'captcha' => array(
                                                                     'captcha' => 'MyImage',
                                                                     'label' => $this->getView()->translate('Rasmdagi belgilarni kiriting'),
                                                                     'required' => true,
                                                                     'wordLen' => 5,
                                                                     'width' => 150,
                                                                     'height' => 40,
                                                                     'timeout' => 300,
                                                                     'fontSize' => 20,
                                                                     'gcFreq' => 5,
                                                                     'dotNoiseLevel' => 0,
                                                                     'lineNoiseLevel' => 0,
                                                                     'background' => 0,
                                                                     'font' => 'files/captcha/fonts/1.ttf',
                                                                     'imgDir' => 'files/captcha/image',
                                                                     'imgUrl' => '/files/captcha/image',
                                                                 )
                                                            ));
        $captcha->setIgnore(true);
        $captcha->setAttrib('class', 'input margin_top_10');

        $text = new Zend_Form_Element_Textarea("text");
        $text->setRequired(true)
                ->addFilter('StringTrim')
                ->setAttrib('class', 'input margin_top_10')
                ->addFilter('StringToLower')
                ->setLabel($this->getView()->translate("Xat matni:"))
                ->setAttrib('maxlength','200')
                ->setAttrib('style','height:100px;width:360px;');

        $button = new Zend_Form_Element_Submit('users_button');
        $button->setLabel($this->getView()->translate('Kiritish'))
                ->setAttrib('class', 'input margin_top_10');

        $this->addElements(array($user_name, $email, $text,$captcha, $button));
        $this->setMethod('post');
        $lang = $_SESSION['Poputchik']['slang'];
        $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/' . $lang . '/default/category/contact');
        $language = $_SESSION['Poputchik']['language'];
        $translator = new Zend_Translate('array', APPLICATION_PATH.'/languages/errors/'.$language.'.php');
        $this->setTranslator($translator);
    }
}
5
  • 2
    Are you using "$yourForm->isValid($formdata)" method in your controller?? Commented Jun 7, 2011 at 10:39
  • what does the error message say? Commented Jun 7, 2011 at 10:41
  • Do your form elements have the "Error" decorator on them? If not, add it and check again. Commented Jun 7, 2011 at 10:43
  • yes I use isValid() function in my controller Commented Jun 7, 2011 at 10:44
  • thanks for all Its working.I wrong use isValid() function. Commented Jun 7, 2011 at 10:53

2 Answers 2

4

in your controller you should use something like

if($this->getRequest()->isPost()){
    if($form->isValid($this->getRequest()->getPost()){
        $values=$form->getValues();
        //do the stuff with (array) $values
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

A primary use case for forms is validating submitted data.

If the submitted data is not valid, it has methods for retrieving the various error codes and messages for elements and sub forms.

To validate a full form, use the isValid() method in your controller action:

if (!$form->isValid($_POST)) {
// failed validation
}

give a look here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.