0

私は Zend の学習を始めたので、これは私がたどったお問い合わせページのリンクです -

私の Zend バージョン - Zend Framework v1.11.11

http://www.tutorial-portal.com/tutorial/show/id/27

コマンドラインを使用してフォームを作成しました-これにより、ファイルの下にzf create form Contactフォルダーが正常に作成されました。コードは次のとおりです- formsContact.phpContact.php

<?php

class Application_Form_Contact extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
        $this->setmethod('post');
        $this->setName('contact-form');

        $this->addElement('text', 'name', array(
                            'label' => 'Please enter your name',
                            'required' => true,
                         ));


        $this->addElement('text', 'email', array(
                            'label' => 'Please enter email address',
                            'required' => true,
                            'validators' => array('EmailAddress'),
                         ));

        $this->addElement('textarea', 'message', array(
                            'label' => 'Please enter your message',
                            'required' => true,
                            'validators' => array( array('validator' => 'StringLength', 'options' => array(0, 20) )
                         ));

        $this->addElement('captcha', 'captcha', array(
                            'label'      => 'Please enter the 5 letters displayed below:',
                            'required'   => true,
                            'captcha'    => array('captcha' => 'Figlet','wordLen' => 5,'timeout' => 300 )
                        ));                                      

        $this->addElement('submit', 'submit', array(
                            'ignore'   => true,
                            'label'    => 'Send Message',
                        ));

        $this->addElement('hash', 'csrf', array(
                            'ignore' => true,
                        ));
    }               
}

ContactController.phpの下にコントローラーを作成しましたC:\xampp\htdocs\projectone\application\controllers。このコントローラのコードは次のようになります -

<?php

class ContactController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        //$form  = new Application_Form_Contact();
        //$this->view->form = $form;

    }

    public function indexAction()
    {
        // action body
        // Create form instance
        $form = new Application_Form_Contact();

        /**
         * Get request
         */
        $request = $this->getRequest();
        $post = $request->getPost(); // This contains the POST params

        /**
         * Check if form was sent
         */
        if ($request->isPost()) {
            /**
             * Check if form is valid
             */
            if ($form->isValid($post)) {
                // build message
                $message = 'From: ' . $post['name'] . chr(10) . 'Email: ' . $post['email'] . chr(10) . 'Message: ' . $post['message'];
                // send mail
                mail('contact@yourwebsite.com', 'contact: ' . $post['subject'], $message);
            }
        }

        // give form to view (needed in index.phtml file)
        $this->view->form = $form;

    }

}

index.phtmlフォルダー構造の下の コードは次のC:\xampp\htdocs\projectone\application\views\scripts\contactようになります-phpタグのコードをエコーし​​ます-echo $this->form

しかし、これはまったく機能していません:(実際に私が間違っていることを見つけることができません。

空白のページのみが表示され、単純な html コンテンツも表示されません。

これは私が使用している URL ですが、残りのコントローラーは正常に動作しています -

http://localhost/projectone/public/contact

PS - 私は Zend の初心者なので、Zend エラーを探す場所と方法がわかりません。これも教えてください :)

4

1 に答える 1

0

さまざまなヒューリスティックを実行し、さまざまなレベルでコードをチェックした後、コードをデバッグできます。問題は実際にはこのLOCにありました-

バグ-

    $this->addElement('textarea', 'message', array(
                        'label' => 'Please enter your message',
                        'required' => true,
                        'validators' => array( array('validator' => 'StringLength', 'options' => array(0, 20) )
                     ));

削除する

'validators' => array( array('validator' => 'StringLength', 'options' => array(0, 20) )

そして、すべてが魅力のようにうまくいきます。

于 2013-01-09T05:50:53.360 に答える