intro
This article shows Multi Page Form that extends Zend_Form.
1.Create Form
Create the file
library/My/Form/MultiPage.php
with the following content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Form.php'</span>; <span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Zend/Session/Namespace.php'</span>; <span style="color: #000000; font-weight: bold;">class</span> My_Form_MultiPage <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form <span style="color: #66cc66;">{</span> const BUTTON_SUBMIT = <span style="color: #ff0000;">'submit'</span>; const BUTTON_NEXT = <span style="color: #ff0000;">'next'</span>; const BUTTON_BACK = <span style="color: #ff0000;">'back'</span>; const BUTTON_CANCEL = <span style="color: #ff0000;">'cancel'</span>; protected <span style="color: #0000ff;">$_name</span> = <span style="color: #000000; font-weight: bold;">null</span>; protected <span style="color: #0000ff;">$_names</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; protected <span style="color: #0000ff;">$_session</span> = <span style="color: #000000; font-weight: bold;">null</span>; protected <span style="color: #0000ff;">$_canceled</span> = <span style="color: #000000; font-weight: bold;">false</span>; protected <span style="color: #0000ff;">$_multi_page</span> = <span style="color: #000000; font-weight: bold;">true</span>; protected <span style="color: #0000ff;">$_submit_decorators</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">'ViewHelper'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'HtmlTag'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'tag'</span> => <span style="color: #ff0000;">'dt'</span>, <span style="color: #ff0000;">'class'</span> => <span style="color: #ff0000;">'submit'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">)</span>; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$multi_page</span> = <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> parent::__construct<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>->_name = <span style="color: #0000ff;">$name</span>; <span style="color: #0000ff;">$this</span>->_multi_page = <span style="color: #0000ff;">$multi_page</span>; <span style="color: #0000ff;">$this</span>->_session = <span style="color: #000000; font-weight: bold;">new</span> Zend_Session_Namespace<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">confirmed</span> = <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _loadForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$form</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">setDefaults</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> protected <span style="color: #000000; font-weight: bold;">function</span> _storeForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$form</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_multi_page<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$form</span> instanceof Zend_Form_SubForm<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$values</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">getValues</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">]</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">getValues</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getValues</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$form</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$name</span>; <span style="color: #0000ff;">$this</span>->_loadForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$form</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">addSubForm</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$form</span>, <span style="color: #0000ff;">$name</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clear<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <a href="http://www.php.net/unset"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">values</span><span style="color: #66cc66;">)</span>; <a href="http://www.php.net/unset"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span><span style="color: #66cc66;">)</span>; <a href="http://www.php.net/unset"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">confirmed</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasForm<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCurrentFormName<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">[</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span><span style="color: #66cc66;">]</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> back<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span> > <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span>--; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_multi_page<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$name</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getCurrentFormName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$form</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getCurrentForm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$result</span> = <span style="color: #0000ff;">$form</span> && <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">isValid</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span>++; <span style="color: #0000ff;">$this</span>->_storeForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$form</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$result</span> = parent::<span style="color: #006600;">isValid</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span> = <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>->_storeForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>, <span style="color: #0000ff;">$this</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$result</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setDefaults<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$values</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$values</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$table_name</span> => <span style="color: #0000ff;">$table_values</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/array_search"><span style="color: #000066;">array_search</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table_name</span>, <span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">)</span> !== <span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$subform</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSubForm</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table_name</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$subform</span>-><span style="color: #006600;">setDefaults</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table_values</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$this</span>->_storeForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$table_name</span>, <span style="color: #0000ff;">$subform</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isFirstForm<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span> == <span style="color: #cc66cc;">0</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isConfirm<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">)</span> <= <span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCurrentForm<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_multi_page && <a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">[</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$subform</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getSubForm</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_names<span style="color: #66cc66;">[</span><span style="color: #0000ff;">$this</span>->_session-><span style="color: #006600;">current</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$subform</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<span style="color: #0000ff;">$this</span>->_multi_page<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #66cc66;">}</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> prepareForm<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$action</span>, <span style="color: #0000ff;">$submit_label</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-><span style="color: #006600;">isConfirm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$form</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$form</span> = <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getCurrentForm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$form</span> instanceof Zend_Form_SubForm<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$subform</span> = <span style="color: #0000ff;">$form</span>; <span style="color: #0000ff;">$form</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">addSubForm</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$subform</span>, <span style="color: #0000ff;">$this</span>-><span style="color: #006600;">getCurrentFormName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">setAction</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$action</span><span style="color: #66cc66;">)</span> -><span style="color: #006600;">setMethod</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'post'</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<span style="color: #0000ff;">$this</span>-><span style="color: #006600;">isFirstForm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$back</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">createElement</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'submit'</span>, self::<span style="color: #006600;">BUTTON_BACK</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$back</span>-><span style="color: #006600;">setLabel</span><span style="color: #66cc66;">(</span>self::<span style="color: #006600;">BUTTON_BACK</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$back</span>-><span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_submit_decorators<span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">addElement</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$back</span><span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-><span style="color: #006600;">isConfirm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$next</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">createElement</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'submit'</span>, <span style="color: #0000ff;">$submit_label</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$next</span>-><span style="color: #006600;">setLabel</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$submit_label</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$next</span>-><span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_submit_decorators<span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$next</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">createElement</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'submit'</span>, self::<span style="color: #006600;">BUTTON_NEXT</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$next</span>-><span style="color: #006600;">setLabel</span><span style="color: #66cc66;">(</span>self::<span style="color: #006600;">BUTTON_NEXT</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$next</span>-><span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_submit_decorators<span style="color: #66cc66;">)</span>; <span style="color: #66cc66;">}</span> <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">addElement</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$next</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$cancel</span> = <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">createElement</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'submit'</span>, self::<span style="color: #006600;">BUTTON_CANCEL</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$cancel</span>-><span style="color: #006600;">setLabel</span><span style="color: #66cc66;">(</span>self::<span style="color: #006600;">BUTTON_CANCEL</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$cancel</span>-><span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>->_submit_decorators<span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$form</span>-><span style="color: #006600;">addElement</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$cancel</span><span style="color: #66cc66;">)</span>; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$form</span>; <span style="color: #66cc66;">}</span> <span style="color: #66cc66;">}</span> |
Next
Next article will show how to use this form class.
History
Date | Content |
---|---|
2008/4/18 | Published |
2008/4/18 | The decorators of submit buttons was changed. |
2008/4/26 | It is modified to use SubForm. |