Zend_Form-StandardElements.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.form.standardElements">
  4. <title>Standard Form Elements Shipped With Zend Framework</title>
  5. <para>
  6. Zend Framework ships with concrete element classes covering most <acronym>HTML</acronym>
  7. form elements. Most simply specify a particular view helper for use when
  8. decorating the element, but several offer additional functionality. The
  9. following is a list of all such classes, as well as descriptions of the
  10. functionality they offer.
  11. </para>
  12. <sect2 id="zend.form.standardElements.button">
  13. <title>Zend_Form_Element_Button</title>
  14. <para>
  15. Used for creating <acronym>HTML</acronym> button elements,
  16. <classname>Zend_Form_Element_Button</classname> extends <link
  17. linkend="zend.form.standardElements.submit">Zend_Form_Element_Submit</link>,
  18. specifying some custom functionality. It specifies the 'formButton'
  19. view helper for decoration.
  20. </para>
  21. <para>
  22. Like the submit element, it uses the element's label as the element
  23. value for display purposes; in other words, to set the text of the
  24. button, set the value of the element. The label will be translated
  25. if a translation adapter is present.
  26. </para>
  27. <para>
  28. Because the label is used as part of the element, the button element
  29. uses only the <link
  30. linkend="zend.form.standardDecorators.viewHelper">ViewHelper</link>
  31. and <link
  32. linkend="zend.form.standardDecorators.dtDdWrapper">DtDdWrapper</link>
  33. decorators.
  34. </para>
  35. <para>
  36. After populating or validating a form, you can check if the given
  37. button was clicked using the <methodname>isChecked()</methodname> method.
  38. </para>
  39. </sect2>
  40. <sect2 id="zend.form.standardElements.captcha">
  41. <title>Zend_Form_Element_Captcha</title>
  42. <para>
  43. CAPTCHAs are used to prevent automated submission of forms by bots
  44. and other automated processes.
  45. </para>
  46. <para>
  47. The Captcha form element allows you to specify which <link
  48. linkend="zend.captcha.adapters">Zend_Captcha adapter</link> you
  49. wish to utilize as a form CAPTCHA. It then sets this adapter as a
  50. validator to the object, and uses a Captcha decorator for rendering
  51. (which proxies to the CAPTCHA adapter).
  52. </para>
  53. <para>
  54. Adapters may be any adapters in <classname>Zend_Captcha</classname>, as well
  55. as any custom adapters you may have defined elsewhere. To allow
  56. this, you may pass an additional plugin loader type key, 'CAPTCHA'
  57. or 'captcha', when specifying a plugin loader prefix path:
  58. </para>
  59. <programlisting language="php"><![CDATA[
  60. $element->addPrefixPath('My_Captcha', 'My/Captcha/', 'captcha');
  61. ]]></programlisting>
  62. <para>
  63. Captcha's may then be registered using the <methodname>setCaptcha()</methodname>
  64. method, which can take either a concrete CAPTCHA instance, or the
  65. short name of a CAPTCHA adapter:
  66. </para>
  67. <programlisting language="php"><![CDATA[
  68. // Concrete instance:
  69. $element->setCaptcha(new Zend_Captcha_Figlet());
  70. // Using shortnames:
  71. $element->setCaptcha('Dumb');
  72. ]]></programlisting>
  73. <para>
  74. If you wish to load your element via configuration, specify either
  75. the key 'captcha' with an array containing the key 'captcha', or
  76. both the keys 'captcha' and 'captchaOptions':
  77. </para>
  78. <programlisting language="php"><![CDATA[
  79. // Using single captcha key:
  80. $element = new Zend_Form_Element_Captcha('foo', array(
  81. 'label' => "Please verify you're a human",
  82. 'captcha' => array(
  83. 'captcha' => 'Figlet',
  84. 'wordLen' => 6,
  85. 'timeout' => 300,
  86. ),
  87. ));
  88. // Using both captcha and captchaOptions:
  89. $element = new Zend_Form_Element_Captcha('foo', array(
  90. 'label' => "Please verify you're a human",
  91. 'captcha' => 'Figlet',
  92. 'captchaOptions' => array(
  93. 'captcha' => 'Figlet',
  94. 'wordLen' => 6,
  95. 'timeout' => 300,
  96. ),
  97. ));
  98. ]]></programlisting>
  99. <para>
  100. The decorator used is determined by querying the captcha adapter. By
  101. default, the <link
  102. linkend="zend.form.standardDecorators.captcha">Captcha
  103. decorator</link> is used, but an adapter may specify a different
  104. one via its <methodname>getDecorator()</methodname> method.
  105. </para>
  106. <para>
  107. As noted, the captcha adapter itself acts as a validator for the
  108. element. Additionally, the NotEmpty validator is not used, and the
  109. element is marked as required. In most cases, you should need to do
  110. nothing else to have a captcha present in your form.
  111. </para>
  112. </sect2>
  113. <sect2 id="zend.form.standardElements.checkbox">
  114. <title>Zend_Form_Element_Checkbox</title>
  115. <para>
  116. <acronym>HTML</acronym> checkboxes allow you return a specific value, but basically
  117. operate as booleans. When checked, the checkbox's value is submitted.
  118. When the checkbox is not checked, nothing is submitted. Internally,
  119. <classname>Zend_Form_Element_Checkbox</classname> enforces this state.
  120. </para>
  121. <para>
  122. By default, the checked value is '1', and the unchecked value '0'.
  123. You can specify the values to use using the <methodname>setCheckedValue()</methodname>
  124. and <methodname>setUncheckedValue()</methodname> accessors, respectively. Internally,
  125. any time you set the value, if the provided value matches the checked value, then it is
  126. set, but any other value causes the unchecked value to be set.
  127. </para>
  128. <para>
  129. Additionally, setting the value sets the <property>checked</property>
  130. property of the checkbox. You can query this using
  131. <methodname>isChecked()</methodname> or simply accessing the property. Using the
  132. <methodname>setChecked($flag)</methodname> method will both set the state of the
  133. flag as well as set the appropriate checked or unchecked value in the
  134. element. Please use this method when setting the checked state of a
  135. checkbox element to ensure the value is set properly.
  136. </para>
  137. <para>
  138. <classname>Zend_Form_Element_Checkbox</classname> uses the 'formCheckbox' view
  139. helper. The checked value is always used to populate it.
  140. </para>
  141. </sect2>
  142. <sect2 id="zend.form.standardElements.file">
  143. <title>Zend_Form_Element_File</title>
  144. <para>
  145. The File form element provides a mechanism for supplying file upload
  146. fields to your form. It utilizes <link
  147. linkend="zend.file.transfer.introduction">Zend_File_Transfer</link>
  148. internally to provide this functionality, and the
  149. <classname>FormFile</classname> view helper as also the <classname>File</classname>
  150. decorator to display the form element.
  151. </para>
  152. <para>
  153. By default, it uses the <classname>Http</classname> transfer adapter, which
  154. introspects the <varname>$_FILES</varname> array and allows you to attach
  155. validators and filters. Validators and filters attached to the form
  156. element are in turn attached to the transfer adapter.
  157. </para>
  158. <example id="zend.form.standardElements.file.usage">
  159. <title>File form element usage</title>
  160. <para>
  161. The above explanation of using the File form element may seem
  162. arcane, but actual usage is relatively trivial:
  163. </para>
  164. <programlisting language="php"><![CDATA[
  165. $element = new Zend_Form_Element_File('foo');
  166. $element->setLabel('Upload an image:')
  167. ->setDestination('/var/www/upload');
  168. // ensure only 1 file
  169. $element->addValidator('Count', false, 1);
  170. // limit to 100K
  171. $element->addValidator('Size', false, 102400);
  172. // only JPEG, PNG, and GIFs
  173. $element->addValidator('Extension', false, 'jpg,png,gif');
  174. $form->addElement($element, 'foo');
  175. ]]></programlisting>
  176. <para>
  177. You also need to ensure that the correct encoding type is provided to
  178. the form; you should use 'multipart/form-data'. You can do this
  179. by setting the 'enctype' attribute on the form:
  180. </para>
  181. <programlisting language="php"><![CDATA[
  182. $form->setAttrib('enctype', 'multipart/form-data');
  183. ]]></programlisting>
  184. <para>
  185. After the form is validated successfully, you must receive the file
  186. to store it in the final destination using <methodname>receive()</methodname>.
  187. Additionally you can determinate the final location using
  188. <methodname>getFileName()</methodname>:
  189. </para>
  190. <programlisting language="php"><![CDATA[
  191. if (!$form->isValid()) {
  192. print "Uh oh... validation error";
  193. }
  194. if (!$form->foo->receive()) {
  195. print "Error receiving the file";
  196. }
  197. $location = $form->foo->getFileName();
  198. ]]></programlisting>
  199. </example>
  200. <note>
  201. <title>Default Upload Location</title>
  202. <para>
  203. By default, files are uploaded to the system temp directory.
  204. </para>
  205. </note>
  206. <note>
  207. <title>File values</title>
  208. <para>
  209. Within <acronym>HTTP</acronym> a file element has no value. For this reason and
  210. because of security concerns <methodname>getValue()</methodname> returns only the
  211. uploaded filename and not the complete path. If you need the file path, call
  212. <methodname>getFileName()</methodname>, which returns both the path and the name of
  213. the file.
  214. </para>
  215. </note>
  216. <note>
  217. <title>Return value of getFileName()</title>
  218. <para>
  219. The result returned by the getFileName() method will change depending on how many files the Zend_Form_Element_File uploaded:
  220. <itemizedlist>
  221. <listitem>
  222. <para>
  223. A single file: string containing the single file name.
  224. </para>
  225. </listitem>
  226. <listitem>
  227. <para>
  228. Multiple files: an array, where each item is a string containing a single file name.
  229. </para>
  230. </listitem>
  231. <listitem>
  232. <para>
  233. No files: an empty array
  234. </para>
  235. </listitem>
  236. </itemizedlist>
  237. </para>
  238. </note>
  239. <para>
  240. Per default the file will automatically be received when you call
  241. <methodname>getValues()</methodname> on the form. The reason behind this behaviour is,
  242. that the file itself is the value of the file element.
  243. </para>
  244. <programlisting language="php"><![CDATA[
  245. $form->getValues();
  246. ]]></programlisting>
  247. <note>
  248. <para>
  249. Therefor another call of <methodname>receive()</methodname> after calling
  250. <methodname>getValues()</methodname> will not have an effect. Also creating a
  251. instance of <classname>Zend_File_Transfer</classname> will not have an effect as
  252. there no file anymore to receive.
  253. </para>
  254. </note>
  255. <para>
  256. Still, sometimes you may want to call <methodname>getValues()</methodname> without
  257. receiving the file. You can archive this by calling
  258. <methodname>setValueDisabled(true)</methodname>. To get the actual value of this flag
  259. you can call <methodname>isValueDisabled()</methodname>.
  260. </para>
  261. <example id="zend.form.standardElements.file.retrievement">
  262. <title>Explicit file retrievement</title>
  263. <para>
  264. First call <methodname>setValueDisabled(true)</methodname>.
  265. </para>
  266. <programlisting language="php"><![CDATA[
  267. $element = new Zend_Form_Element_File('foo');
  268. $element->setLabel('Upload an image:')
  269. ->setDestination('/var/www/upload')
  270. ->setValueDisabled(true);
  271. ]]></programlisting>
  272. <para>
  273. Now the file will not be received when you call
  274. <methodname>getValues()</methodname>. So you must call
  275. <methodname>receive()</methodname> on the file element, or an instance of
  276. <classname>Zend_File_Transfer</classname> yourself.
  277. </para>
  278. <programlisting language="php"><![CDATA[
  279. $values = $form->getValues();
  280. if ($form->isValid($form->getPost())) {
  281. if (!$form->foo->receive()) {
  282. print "Upload error";
  283. }
  284. }
  285. ]]></programlisting>
  286. </example>
  287. <para>
  288. There are several states of the uploaded file which can be checked
  289. with the following methods:
  290. </para>
  291. <itemizedlist>
  292. <listitem>
  293. <para>
  294. <methodname>isUploaded()</methodname>: Checks if the file element has
  295. been uploaded or not.
  296. </para>
  297. </listitem>
  298. <listitem>
  299. <para>
  300. <methodname>isReceived()</methodname>: Checks if the file element has
  301. already been received.
  302. </para>
  303. </listitem>
  304. <listitem>
  305. <para>
  306. <methodname>isFiltered()</methodname>: Checks if the filters have already
  307. been applied to the file element or not.
  308. </para>
  309. </listitem>
  310. </itemizedlist>
  311. <example id="zend.form.standardElements.file.isuploaded">
  312. <title>Checking if an optional file has been uploaded</title>
  313. <programlisting language="php"><![CDATA[
  314. $element = new Zend_Form_Element_File('foo');
  315. $element->setLabel('Upload an image:')
  316. ->setDestination('/var/www/upload')
  317. ->setRequired(false);
  318. $element->addValidator('Size', false, 102400);
  319. $form->addElement($element, 'foo');
  320. // The foo file element is optional but when it's given go into here
  321. if ($form->foo->isUploaded()) {
  322. // foo file given... do something
  323. }
  324. ]]></programlisting>
  325. </example>
  326. <para>
  327. <classname>Zend_Form_Element_File</classname> also supports multiple files.
  328. By calling the <methodname>setMultiFile($count)</methodname> method you can set
  329. the number of file elements you want to create. This keeps you
  330. from setting the same settings multiple times.
  331. </para>
  332. <example id="zend.form.standardElements.file.multiusage">
  333. <title>Setting multiple files</title>
  334. <para>
  335. Creating a multifile element is the same as setting a single element.
  336. Just call <methodname>setMultiFile()</methodname> after the element is created:
  337. </para>
  338. <programlisting language="php"><![CDATA[
  339. $element = new Zend_Form_Element_File('foo');
  340. $element->setLabel('Upload an image:')
  341. ->setDestination('/var/www/upload');
  342. // ensure minimum 1, maximum 3 files
  343. $element->addValidator('Count', false, array('min' => 1, 'max' => 3));
  344. // limit to 100K
  345. $element->addValidator('Size', false, 102400);
  346. // only JPEG, PNG, and GIFs
  347. $element->addValidator('Extension', false, 'jpg,png,gif');
  348. // defines 3 identical file elements
  349. $element->setMultiFile(3);
  350. $form->addElement($element, 'foo');
  351. ]]></programlisting>
  352. <para>
  353. You now have 3 identical file upload elements
  354. with the same settings. To get the set multifile number simply call
  355. <methodname>getMultiFile()</methodname>.
  356. </para>
  357. </example>
  358. <note>
  359. <title>File elements in Subforms</title>
  360. <para>
  361. When you use file elements in subforms you must set unique names.
  362. For example, if you name a file element in subform1 "file", you must give
  363. any file element in subform2 a different name.
  364. </para>
  365. <para>
  366. If there are 2 file elements with the same name, the second
  367. element is not be displayed or submitted.
  368. </para>
  369. <para>
  370. Additionally, file elements are not rendered within the sub-form. So when
  371. you add a file element into a subform, then the element will be rendered
  372. within the main form.
  373. </para>
  374. </note>
  375. <para>
  376. To limit the size of the file uploaded, you can
  377. specify the maximum file size by setting the <constant>MAX_FILE_SIZE</constant>
  378. option on the form. When you set this value by using the
  379. <methodname>setMaxFileSize($size)</methodname> method, it will be rendered with the
  380. file element.
  381. </para>
  382. <programlisting language="php"><![CDATA[
  383. $element = new Zend_Form_Element_File('foo');
  384. $element->setLabel('Upload an image:')
  385. ->setDestination('/var/www/upload')
  386. ->addValidator('Size', false, 102400) // limit to 100K
  387. ->setMaxFileSize(102400); // limits the filesize on the client side
  388. $form->addElement($element, 'foo');
  389. ]]></programlisting>
  390. <note>
  391. <title>MaxFileSize with Multiple File Elements</title>
  392. <para>
  393. When you use multiple file elements in your form you should set
  394. the <constant>MAX_FILE_SIZE</constant> only once. Setting it again will
  395. overwrite the previous value.
  396. </para>
  397. <para>
  398. Note, that this is also the case when you use multiple forms.
  399. </para>
  400. </note>
  401. </sect2>
  402. <sect2 id="zend.form.standardElements.hidden">
  403. <title>Zend_Form_Element_Hidden</title>
  404. <para>
  405. Hidden elements inject data that should be submitted, but that should not manipulated by
  406. the user . <classname>Zend_Form_Element_Hidden</classname> accomplishes this with the
  407. 'formHidden' view helper.
  408. </para>
  409. </sect2>
  410. <sect2 id="zend.form.standardElements.hash">
  411. <title>Zend_Form_Element_Hash</title>
  412. <para>
  413. This element provides protection from CSRF attacks on forms,
  414. ensuring the data is submitted by the user session that generated
  415. the form and not by a rogue script. Protection is achieved by adding
  416. a hash element to a form and verifying it when the form is
  417. submitted.
  418. </para>
  419. <para>
  420. The name of the hash element should be unique. We recommend using
  421. the <literal>salt</literal> option for the element- two hashes with
  422. same names and different salts would not collide:
  423. </para>
  424. <programlisting language="php"><![CDATA[
  425. $form->addElement('hash', 'no_csrf_foo', array('salt' => 'unique'));
  426. ]]></programlisting>
  427. <para>
  428. You can set the salt later using the <methodname>setSalt($salt)</methodname>
  429. method.
  430. </para>
  431. <para>
  432. Internally, the element stores a unique identifier using
  433. <classname>Zend_Session_Namespace</classname>, and checks for it at
  434. submission (checking that the TTL has not expired). The 'Identical'
  435. validator is then used to ensure the submitted hash matches the
  436. stored hash.
  437. </para>
  438. <para>
  439. The 'formHidden' view helper is used to render the element in the
  440. form.
  441. </para>
  442. <note>
  443. <title>Testing forms containing Zend_Form_Element_Hash</title>
  444. <para>
  445. When unit testing a form containing a <classname>Zend_Form_Element_Hash</classname>
  446. it is necessary to call <methodname>initCsrfToken</methodname> and
  447. <methodname>initCsrfValidator</methodname> before attempting to
  448. validate the form. The hash value of the <classname>Zend_Form_Element_Hash</classname>
  449. element must also be injected into the array of values passed as the
  450. argument to <methodname>Zend_Form::isValid</methodname>
  451. </para>
  452. <example id="zend.form.standardElements.hash.unittesting">
  453. <title>Simple example of testing a CSRF-protected form</title>
  454. <programlisting language="php"><![CDATA[
  455. public function testCsrfProtectedForm()
  456. {
  457. $form = new Zend_Form();
  458. $form->addElement(new Zend_Form_Element_Hash('csrf'));
  459. $csrf = $form->getElement('csrf');
  460. $csrf->initCsrfToken();
  461. $csrf->initCsrfValidator();
  462. $this->assertTrue($form->isValid(array(
  463. 'csrf' => $csrf->getHash()
  464. )));
  465. }]]></programlisting>
  466. </example>
  467. </note>
  468. </sect2>
  469. <sect2 id="zend.form.standardElements.Image">
  470. <title>Zend_Form_Element_Image</title>
  471. <para>
  472. Images can be used as form elements, and you can use these images as
  473. graphical elements on form buttons.
  474. </para>
  475. <para>
  476. Images need an image source. <classname>Zend_Form_Element_Image</classname>
  477. allows you to specify this by using the <methodname>setImage()</methodname>
  478. accessor (or 'image' configuration key). You can also optionally specify a value to use
  479. when submitting the image using the <methodname>setImageValue()</methodname> accessor
  480. (or 'imageValue' configuration key). When the value set for the
  481. element matches the <property>imageValue</property>, then the accessor
  482. <methodname>isChecked()</methodname> will return <constant>TRUE</constant>.
  483. </para>
  484. <para>
  485. Image elements use the
  486. <link linkend="zend.form.standardDecorators.image">Image
  487. Decorator</link> for rendering, in addition to the standard Errors,
  488. HtmlTag, and Label decorators. You can optionally specify a tag to
  489. the <classname>Image</classname> decorator that will then wrap the image
  490. element.
  491. </para>
  492. </sect2>
  493. <sect2 id="zend.form.standardElements.multiCheckbox">
  494. <title>Zend_Form_Element_MultiCheckbox</title>
  495. <para>
  496. Often you have a set of related checkboxes, and you wish to group
  497. the results. This is much like a <link
  498. linkend="zend.form.standardElements.multiselect">Multiselect</link>,
  499. but instead of them being in a dropdown list, you need to show
  500. checkbox/value pairs.
  501. </para>
  502. <para>
  503. <classname>Zend_Form_Element_MultiCheckbox</classname> makes this a snap. Like
  504. all other elements extending the base Multi element, you can specify
  505. a list of options, and easily validate against that same list. The
  506. 'formMultiCheckbox' view helper ensures that these are returned as
  507. an array in the form submission.
  508. </para>
  509. <para>
  510. By default, this element registers an <classname>InArray</classname> validator
  511. which validates against the array keys of registered options. You
  512. can disable this behavior by either calling
  513. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  514. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  515. configuration key.
  516. </para>
  517. <para>
  518. You may manipulate the various checkbox options using the following
  519. methods:
  520. </para>
  521. <itemizedlist>
  522. <listitem>
  523. <para><methodname>addMultiOption($option, $value)</methodname></para>
  524. </listitem>
  525. <listitem>
  526. <para><methodname>addMultiOptions(array $options)</methodname></para>
  527. </listitem>
  528. <listitem>
  529. <para>
  530. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  531. options)
  532. </para>
  533. </listitem>
  534. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  535. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  536. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  537. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  538. </itemizedlist>
  539. <para>
  540. To mark checked items, you need to pass an array of values to
  541. <methodname>setValue()</methodname>. The following will check the values "bar"
  542. and "bat":
  543. </para>
  544. <programlisting language="php"><![CDATA[
  545. $element = new Zend_Form_Element_MultiCheckbox('foo', array(
  546. 'multiOptions' => array(
  547. 'foo' => 'Foo Option',
  548. 'bar' => 'Bar Option',
  549. 'baz' => 'Baz Option',
  550. 'bat' => 'Bat Option',
  551. )
  552. ));
  553. $element->setValue(array('bar', 'bat'));
  554. ]]></programlisting>
  555. <para>
  556. Note that even when setting a single value, you must pass an array.
  557. </para>
  558. </sect2>
  559. <sect2 id="zend.form.standardElements.multiselect">
  560. <title>Zend_Form_Element_Multiselect</title>
  561. <para>
  562. <acronym>XHTML</acronym> <emphasis>select</emphasis> elements allow a 'multiple'
  563. attribute, indicating multiple options may be selected for submission, instead
  564. of the usual one. <classname>Zend_Form_Element_Multiselect</classname> extends
  565. <link
  566. linkend="zend.form.standardElements.select">Zend_Form_Element_Select</link>,
  567. and sets the <property>multiple</property> attribute to 'multiple'. Like
  568. other classes that inherit from the base
  569. <classname>Zend_Form_Element_Multi</classname> class, you can manipulate the
  570. options for the select using:
  571. </para>
  572. <itemizedlist>
  573. <listitem>
  574. <para><methodname>addMultiOption($option, $value)</methodname></para>
  575. </listitem>
  576. <listitem>
  577. <para><methodname>addMultiOptions(array $options)</methodname></para>
  578. </listitem>
  579. <listitem>
  580. <para>
  581. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  582. options)
  583. </para>
  584. </listitem>
  585. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  586. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  587. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  588. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  589. </itemizedlist>
  590. <para>
  591. If a translation adapter is registered with the form and/or element,
  592. option values will be translated for display purposes.
  593. </para>
  594. <para>
  595. By default, this element registers an <classname>InArray</classname> validator
  596. which validates against the array keys of registered options. You
  597. can disable this behavior by either calling
  598. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  599. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  600. configuration key.
  601. </para>
  602. </sect2>
  603. <sect2 id="zend.form.standardElements.password">
  604. <title>Zend_Form_Element_Password</title>
  605. <para>
  606. Password elements are basically normal text elements -- except that
  607. you typically do not want the submitted password displayed in error
  608. messages or the element itself when the form is re-displayed.
  609. </para>
  610. <para>
  611. <classname>Zend_Form_Element_Password</classname> achieves this by calling
  612. <methodname>setObscureValue(true)</methodname> on each validator (ensuring that
  613. the password is obscured in validation error messages), and using
  614. the 'formPassword' view helper (which does not display the value
  615. passed to it).
  616. </para>
  617. </sect2>
  618. <sect2 id="zend.form.standardElements.radio">
  619. <title>Zend_Form_Element_Radio</title>
  620. <para>
  621. Radio elements allow you to specify several options, of which you
  622. need a single value returned. <classname>Zend_Form_Element_Radio</classname>
  623. extends the base <classname>Zend_Form_Element_Multi</classname> class,
  624. allowing you to specify a number of options, and then uses the
  625. <emphasis>formRadio</emphasis> view helper to display these.
  626. </para>
  627. <para>
  628. By default, this element registers an <classname>InArray</classname> validator
  629. which validates against the array keys of registered options. You
  630. can disable this behavior by either calling
  631. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  632. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  633. configuration key.
  634. </para>
  635. <para>
  636. Like all elements extending the Multi element base class, the
  637. following methods may be used to manipulate the radio options
  638. displayed:
  639. </para>
  640. <itemizedlist>
  641. <listitem>
  642. <para><methodname>addMultiOption($option, $value)</methodname></para>
  643. </listitem>
  644. <listitem>
  645. <para><methodname>addMultiOptions(array $options)</methodname></para>
  646. </listitem>
  647. <listitem>
  648. <para>
  649. <methodname>setMultiOptions(array $options)</methodname>
  650. (overwrites existing options)
  651. </para>
  652. </listitem>
  653. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  654. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  655. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  656. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  657. </itemizedlist>
  658. </sect2>
  659. <sect2 id="zend.form.standardElements.reset">
  660. <title>Zend_Form_Element_Reset</title>
  661. <para>
  662. Reset buttons are typically used to clear a form, and are not part
  663. of submitted data. However, as they serve a purpose in the display,
  664. they are included in the standard elements.
  665. </para>
  666. <para>
  667. <classname>Zend_Form_Element_Reset</classname> extends <link
  668. linkend="zend.form.standardElements.submit">Zend_Form_Element_Submit</link>.
  669. As such, the label is used for the button display, and will be
  670. translated if a translation adapter is present. It utilizes only the
  671. 'ViewHelper' and 'DtDdWrapper' decorators, as there should never be
  672. error messages for such elements, nor will a label be necessary.
  673. </para>
  674. </sect2>
  675. <sect2 id="zend.form.standardElements.select">
  676. <title>Zend_Form_Element_Select</title>
  677. <para>
  678. Select boxes are a common way of limiting to specific choices for a
  679. given form datum. <classname>Zend_Form_Element_Select</classname> allows you
  680. to generate these quickly and easily.
  681. </para>
  682. <para>
  683. By default, this element registers an <classname>InArray</classname> validator
  684. which validates against the array keys of registered options. You
  685. can disable this behavior by either calling
  686. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  687. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  688. configuration key.
  689. </para>
  690. <para>
  691. As it extends the base Multi element, the following methods may be
  692. used to manipulate the select options:
  693. </para>
  694. <itemizedlist>
  695. <listitem>
  696. <para><methodname>addMultiOption($option, $value)</methodname></para>
  697. </listitem>
  698. <listitem>
  699. <para><methodname>addMultiOptions(array $options)</methodname></para>
  700. </listitem>
  701. <listitem>
  702. <para>
  703. <methodname>setMultiOptions(array $options)</methodname>
  704. (overwrites existing options)
  705. </para>
  706. </listitem>
  707. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  708. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  709. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  710. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  711. </itemizedlist>
  712. <para>
  713. <classname>Zend_Form_Element_Select</classname> uses the 'formSelect' view
  714. helper for decoration.
  715. </para>
  716. </sect2>
  717. <sect2 id="zend.form.standardElements.submit">
  718. <title>Zend_Form_Element_Submit</title>
  719. <para>
  720. Submit buttons are used to submit a form. You may use multiple
  721. submit buttons; you can use the button used to submit the form to
  722. decide what action to take with the data submitted.
  723. <classname>Zend_Form_Element_Submit</classname> makes this decisioning easy,
  724. by adding a <methodname>isChecked()</methodname> method; as only one button
  725. element will be submitted by the form, after populating or
  726. validating the form, you can call this method on each submit button
  727. to determine which one was used.
  728. </para>
  729. <para>
  730. <classname>Zend_Form_Element_Submit</classname> uses the label as the "value"
  731. of the submit button, translating it if a translation adapter is
  732. present. <methodname>isChecked()</methodname> checks the submitted value against
  733. the label in order to determine if the button was used.
  734. </para>
  735. <para>
  736. The <link
  737. linkend="zend.form.standardDecorators.viewHelper">ViewHelper</link>
  738. and <link
  739. linkend="zend.form.standardDecorators.dtDdWrapper">DtDdWrapper</link>
  740. decorators to render the element. No label decorator is used, as the
  741. button label is used when rendering the element; also, typically,
  742. you will not associate errors with a submit element.
  743. </para>
  744. </sect2>
  745. <sect2 id="zend.form.standardElements.text">
  746. <title>Zend_Form_Element_Text</title>
  747. <para>
  748. By far the most prevalent type of form element is the text element,
  749. allowing for limited text entry; it's an ideal element for most data
  750. entry. <classname>Zend_Form_Element_Text</classname> simply uses the
  751. 'formText' view helper to display the element.
  752. </para>
  753. </sect2>
  754. <sect2 id="zend.form.standardElements.textarea">
  755. <title>Zend_Form_Element_Textarea</title>
  756. <para>
  757. Textareas are used when large quantities of text are expected, and
  758. place no limits on the amount of text submitted (other than maximum
  759. size limits as dictated by your server or <acronym>PHP</acronym>).
  760. <classname>Zend_Form_Element_Textarea</classname> uses the 'textArea' view
  761. helper to display such elements, placing the value as the content of
  762. the element.
  763. </para>
  764. </sect2>
  765. </sect1>
  766. <!--
  767. vim:se ts=4 sw=4 tw=80 et:
  768. -->