私は Zend の学習を始めたので、これは私がたどったお問い合わせページのリンクです -
私の Zend バージョン - Zend Framework v1.11.11
http://www.tutorial-portal.com/tutorial/show/id/27
コマンドラインを使用してフォームを作成しました-これにより、ファイルの下にzf create form Contact
フォルダーが正常に作成されました。コードは次のとおりです- forms
Contact.php
Contact.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 エラーを探す場所と方法がわかりません。これも教えてください :)