ไฟล์ IndexController.php
public function signinAction()
{
// action body
$signinform = new Form_Signin();
$signinform->setAction('/public/index/signin');
if($this->getRequest()->isPost()){
if($signinform->isValid($_POST)){
$data = $signinform->getValues();
print_r($data);
}
}
$this->view->form = $signinform;
}
ไฟล์ Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutload()
{
$autoLoader = Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' =>'',
'resourceTypes' => array(
'form' => array(
'path' => 'forms/',
'namespace' => 'Form_',
), ), ));
return $autoLoader;
}
}
ไฟล์ signin.phtml
<div class="container">
<h2 class="form-signin-heading">เข้าสู่ระบบ</h2>
<?php echo $this->form; ?>
</div> <!-- /container -->
ไฟล์ Signin.php
class Form_Signin extends Zend_Form
{
public function init()
{
$email = $this->createElement('text','email',array(
'placeholder' => 'Email address',
'class' => 'form-control',
));
$email->setRequired(TRUE);
$email->addValidator('StringLength',false, array(6,40));
$email->addFilters(array(
new Zend_Filter_StringTrim(),
new Zend_Filter_StringTolower()
));
$email->setDecorators(array('ViewHelper', 'Error', 'Label'));
//---------------------------------------------------------------
$password = $this->createElement('password','password',array(
'placeholder' => 'password',
'class' => 'form-control',
));
$password->setRequired(TRUE);
$password->addValidator('StringLength',false, array(6,20));
$password->addFilters('StringToLower');
$password->setDecorators(array('ViewHelper', 'Error', 'Label'));
$this->addElement($password);
}
}
สร้างฟอร์มด้วย zendform ไม่ขึ้นเลยครับ รบกวนช่วยดูให้ทีครับ
public function signinAction()
{
// action body
$signinform = new Form_Signin();
$signinform->setAction('/public/index/signin');
if($this->getRequest()->isPost()){
if($signinform->isValid($_POST)){
$data = $signinform->getValues();
print_r($data);
}
}
$this->view->form = $signinform;
}
ไฟล์ Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutload()
{
$autoLoader = Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' =>'',
'resourceTypes' => array(
'form' => array(
'path' => 'forms/',
'namespace' => 'Form_',
), ), ));
return $autoLoader;
}
}
ไฟล์ signin.phtml
<div class="container">
<h2 class="form-signin-heading">เข้าสู่ระบบ</h2>
<?php echo $this->form; ?>
</div> <!-- /container -->
ไฟล์ Signin.php
class Form_Signin extends Zend_Form
{
public function init()
{
$email = $this->createElement('text','email',array(
'placeholder' => 'Email address',
'class' => 'form-control',
));
$email->setRequired(TRUE);
$email->addValidator('StringLength',false, array(6,40));
$email->addFilters(array(
new Zend_Filter_StringTrim(),
new Zend_Filter_StringTolower()
));
$email->setDecorators(array('ViewHelper', 'Error', 'Label'));
//---------------------------------------------------------------
$password = $this->createElement('password','password',array(
'placeholder' => 'password',
'class' => 'form-control',
));
$password->setRequired(TRUE);
$password->addValidator('StringLength',false, array(6,20));
$password->addFilters('StringToLower');
$password->setDecorators(array('ViewHelper', 'Error', 'Label'));
$this->addElement($password);
}
}