Home > PHP
PHP Archive
[ZF] Zend_Form : Remove the submit-button value from url parameters
- 2010-11-26 (金)
- Zend Framework
Zend_Formでフォームエレメントを作る場合にはnameが必須なんだけど、
GET送信するとnameがあるばかりにボタンまでURLに含まれてしまうので
Redirectorによる回避策を試してみた。
検索のフォーム。methodをpostにする。
-
class Application_Form_Search extends Zend_Form
-
{
-
functions init(){
-
$this->setMethod('post')
-
->clearDecorators()
-
->addDecorator('FormElements')
-
->addDecorator('Form');
-
-
'label' => 'Keyword',
-
'required' => true
-
));
-
-
$this->addElement('submit',
-
'submit',
-
'label' => 'Search',
-
'required' => false,
-
'ignore' => true
-
)
-
);
-
}
-
}
検索する場所は仮にindexとして、index.phtmlには検索フォームを表示しておく。
getRequest()->isPost()で送信された値があり、バリーデーションもtrueなら
送信された値($params)からボタンを削除(unset)する。
アクションヘルパーのRedirectorに$paramsを渡してsearchActionにリダイレクトする。
-
public function indexAction()
-
{
-
$this->view->searchForm = $this->_searchForm;
-
-
$request = $this->getRequest();
-
$params = $request->getPost();
-
-
if($request->isPost() && $this->_searchForm->isValid($params)){
-
$this->_helper->Redirector->setGotoSimple('search', null, null, $params);
-
}else{
-
$this->view->data = $this->_mapper->fetchAll();
-
}
-
}
※$this->_searchForm ---> instance of Application_Form_Search
※$this->_mapper ---> instance of DataMapper
searchActionに飛ばされた時、検索キーはZendライクなGETパラメーター(/key/value/のパターン)になっているので、
getRequest()->getParams()でキーワードとかを取り出して使う。
-
public function searchAction()
-
{
-
$request = $this->getRequest();
-
$params = $request->getParams();
-
-
$this->view->data = $this->_mapper->search($params);
-
$this->view->searchForm = $this->_searchForm->populate($params);
-
-
$this->render('index');
-
-
}
- Comments: 0
- Trackbacks: 0
[ZF] Zend_View HeadTitle method tips
- 2010-11-24 (水)
- Zend Framework
ページタイトルの設定をするビューヘルパーのHeadTitleについていろいろ。
基本
headTitleでページタイトルを設定。
controller:
-
$this->view->headTitle('Site Name');
Output:
-
<title>Site Name</title>
- Comments: 0
- Trackbacks: 0
[ZF] Zend_Form 要素に対するデコレータの設定についての色々
- 2010-11-19 (金)
- Zend Framework
最近Zend Frameworkを使い始めたんですがね、
Form要素を作る時、日本人的にはテーブルの方がしっくりくるじゃないですか?
バリデーションに続き海外製では良くあることですが、Zend_Formはデフォルトが定義リストなんです。
出力はラベルとフォーム要素のペアで、ラベルを指定しなかった場合はラベルのテキストが空白文字になります。
dtが空っぽだなんて気になるじゃないですか。私だけですか?
まあ兎に角自分好みにマークアップすべく、Zend_Formを調教してみることにしたわけです。
Default
これはクイックスタートで作るGuestBookのsignフォームです。
テキストボックスの角丸とか必須入力の赤文字とかはCSSの効果です。
- Comments: 0
- Trackbacks: 1
[ZF] Zend_Validator 日本式電話番号バリデーター
- 2010-11-18 (木)
- Zend Framework
Zend Frameworkで日本式の電話番号のフォーマットチェックをするプラグイン。
欲しい感じのが無かったからこの記事参考にして作ってみた。半角全角チェック、ハイフンの有無について指定できます。
- Comments: 0
- Trackbacks: 0
[PHP5] OOPで掲示板を作ってみる - Step8:ページング
- 2010-11-17 (水)
- OOPでBBS
オブジェクト指向プログラミングでフレームワークを使わずに掲示板を作るよその8。
ページングって面倒だよね。
目次
- Comments: 0
- Trackbacks: 0
ホーム > PHP
-
- まとめ
- ホームページビルダー
- 初音ミク
- 擬似クラス
- 楽天
- 1Column
- 2BOX
- 2ch
- 2column
- 2Helvs
- 3column
- 5BOX
- Actionscript
- Ajax
- Animation
- AntiSpam
- API
- apple
- Aptana
- Aqua
- ASCII
- Assets
- AutoExternalLink
- background
- backup
- BETA
- Blog Status
- breadcrumb
- Bubble
- bug
- Button
- calendar
- Calendarizm
- canvas
- Center
- Chain
- Chrome
- Class
- Click Event
- CMS
- ColorMeShopPro
- ContactForm
- Control
- Cookie
- CSS
- CSS3
- CSV
- Custom
- date()
- Demo
- Dojo
- domain
- Download
- Dreamweaver
- dropdown
- Dummy Text
- Effect
- Elastic
- Error
- Filter
- filter.html
- FireFox
- Fixed
- Flash
- Floating
- foglio
- Form
- free material
- free script
- Function Reference
- Fx.Morph
- Fx.Scroll
- Fx.Slide
- Fx.Tween
- Game
- gettext
- get_posts
- GMarker
- Go-To-Top
- GoogleChart
- GoogleEarth
- GoogleMap
- GoogleSearch
- Hack
- Halves
- Highlight
- Horizontal
- HTML&XHTML
- HTML5
- HTML5API
- Icon
- IE
- illustrator
- infowindow
- iphone
- Javascript
- jQuery
- jQuery.plugin
- jsdo.it
- KML
- LeftMenu
- liquid
- ListMenu
- Localization
- login-system
- Magpie RSS
- Mobile
- mooFollow
- MooTools
- mooTyping
- number format()
- OnlineGame
- OOP
- OpenPNE
- Pagenation
- permalink
- Photoshop
- PHP
- ping
- plugin
- poedit
- Polyline
- prototype.js
- Regular Expression
- RightMenu
- rollover
- RPC
- RSS
- Safari
- Sample
- script.aculo.us
- scrollbar
- selection
- selectors
- SEO
- session
- Shortcode
- Sidebar Widgets
- slimbbs
- Smarty
- SmoothScroll
- strtotime()
- Symphony-CMS
- Tableless
- Tab Menu
- Tar
- Template
- Template Engine
- Template Tags
- time()
- TinyMCE
- token
- Tooltip
- Transparent
- Tutorial
- Tutoriarl
- Valid
- Validator
- vertical-align
- Web Browser
- Web Site
- Wiki
- window.open
- wordpress
- wp-custom
- wp-function
- wp-plugin
- wp-themes
- xampp
- XHTML
- XML
- Xserver
- YouTube
- YUI
- Zend Framework
- Zend_Form
- Zend_View
- zeromail

