Zend_Form-StandardElements.xml 36 KB

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