ตัวอย่างต่อไปนี้เป็นการสร้างฟอร์มรับค่าจากยูเซอร์ และ Post ไปยัง Controller เพื่อประมวลผล แล้วส่งกลับมายัง veiws/scripts
1. สืบเนื่องจากการใช้ layout ให้สร้างไฟล์ views/scripts/index/simpleform.phtml ดังนี้
โค้ด: เลือกทั้งหมด
<div id="header">
<img src="stage-logo.gif" width="187" height="29" alt="Stage & Screen" class="logo" />
<span class="strapline">theatre and film reviews</span>
</div>
<!-- Start Simple form -->
โค้ด: เลือกทั้งหมด
<div id="content">
<h1>ตัวอย่าง Scripts Basic Form</h1>
<div align="center">
<?php if ( $this->URL ) {
echo "<h1>POST Result:: $this->URL</h1>" ; } ?>
<form method="POST" action="/index/simpleform" name="mainform"> URL To Go:
<input name="url" id="url" value="http://www.ssup.com">
<input type="Submit" name="submit" id="submit" value="Go" >
</form>
</div>
</div>
<!-- End Simple form -->
<div id="nav">
<ul>
<li><a href="#">Play Reviews</a></li>
<li><a href="#">Film Reviews</a></li>
<li><a href="#">Post a Review</a></li>
<li><a href="#">About this site</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
<h2>Latest Reviews</h2>
<ul>
<li><a href="#">The Passion of The Christ</a></li>
<li><a href="#">Finding Nemo</a></li>
<li><a href="#">Stomp</a></li>
<li><a href="#">The Lion King 3</a></li>
</ul>
</div>
โค้ด: เลือกทั้งหมด
public function simpleformAction()
{
$this->_helper->layout->setLayout('page2_layout');
if ($this->_request->isPost()) {
//$url = Zend_Filter::get($this->getRequest()->getPost('url'), 'StripTags');
$url = Zend_Filter::filterStatic($this->getRequest()->getPost('url'), 'StripTags'); //ZF > 1.9.0
$this->view->assign('URL', $url) ;
}
}//simple form
http://localhost/index/simpleform
ถ้าถูกต้องก็จะขึ้นฟอร์มให้กรอกข้อมูล และ submit ได้