Zend_Form-StandardElements.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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. </sect2>
  443. <sect2 id="zend.form.standardElements.Image">
  444. <title>Zend_Form_Element_Image</title>
  445. <para>
  446. Images can be used as form elements, and you can use these images as
  447. graphical elements on form buttons.
  448. </para>
  449. <para>
  450. Images need an image source. <classname>Zend_Form_Element_Image</classname>
  451. allows you to specify this by using the <methodname>setImage()</methodname>
  452. accessor (or 'image' configuration key). You can also optionally specify a value to use
  453. when submitting the image using the <methodname>setImageValue()</methodname> accessor
  454. (or 'imageValue' configuration key). When the value set for the
  455. element matches the <property>imageValue</property>, then the accessor
  456. <methodname>isChecked()</methodname> will return <constant>TRUE</constant>.
  457. </para>
  458. <para>
  459. Image elements use the
  460. <link linkend="zend.form.standardDecorators.image">Image
  461. Decorator</link> for rendering, in addition to the standard Errors,
  462. HtmlTag, and Label decorators. You can optionally specify a tag to
  463. the <classname>Image</classname> decorator that will then wrap the image
  464. element.
  465. </para>
  466. </sect2>
  467. <sect2 id="zend.form.standardElements.multiCheckbox">
  468. <title>Zend_Form_Element_MultiCheckbox</title>
  469. <para>
  470. Often you have a set of related checkboxes, and you wish to group
  471. the results. This is much like a <link
  472. linkend="zend.form.standardElements.multiselect">Multiselect</link>,
  473. but instead of them being in a dropdown list, you need to show
  474. checkbox/value pairs.
  475. </para>
  476. <para>
  477. <classname>Zend_Form_Element_MultiCheckbox</classname> makes this a snap. Like
  478. all other elements extending the base Multi element, you can specify
  479. a list of options, and easily validate against that same list. The
  480. 'formMultiCheckbox' view helper ensures that these are returned as
  481. an array in the form submission.
  482. </para>
  483. <para>
  484. By default, this element registers an <classname>InArray</classname> validator
  485. which validates against the array keys of registered options. You
  486. can disable this behavior by either calling
  487. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  488. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  489. configuration key.
  490. </para>
  491. <para>
  492. You may manipulate the various checkbox options using the following
  493. methods:
  494. </para>
  495. <itemizedlist>
  496. <listitem>
  497. <para><methodname>addMultiOption($option, $value)</methodname></para>
  498. </listitem>
  499. <listitem>
  500. <para><methodname>addMultiOptions(array $options)</methodname></para>
  501. </listitem>
  502. <listitem>
  503. <para>
  504. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  505. options)
  506. </para>
  507. </listitem>
  508. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  509. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  510. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  511. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  512. </itemizedlist>
  513. <para>
  514. To mark checked items, you need to pass an array of values to
  515. <methodname>setValue()</methodname>. The following will check the values "bar"
  516. and "bat":
  517. </para>
  518. <programlisting language="php"><![CDATA[
  519. $element = new Zend_Form_Element_MultiCheckbox('foo', array(
  520. 'multiOptions' => array(
  521. 'foo' => 'Foo Option',
  522. 'bar' => 'Bar Option',
  523. 'baz' => 'Baz Option',
  524. 'bat' => 'Bat Option',
  525. );
  526. ));
  527. $element->setValue(array('bar', 'bat'));
  528. ]]></programlisting>
  529. <para>
  530. Note that even when setting a single value, you must pass an array.
  531. </para>
  532. </sect2>
  533. <sect2 id="zend.form.standardElements.multiselect">
  534. <title>Zend_Form_Element_Multiselect</title>
  535. <para>
  536. <acronym>XHTML</acronym> <emphasis>select</emphasis> elements allow a 'multiple'
  537. attribute, indicating multiple options may be selected for submission, instead
  538. of the usual one. <classname>Zend_Form_Element_Multiselect</classname> extends
  539. <link
  540. linkend="zend.form.standardElements.select">Zend_Form_Element_Select</link>,
  541. and sets the <property>multiple</property> attribute to 'multiple'. Like
  542. other classes that inherit from the base
  543. <classname>Zend_Form_Element_Multi</classname> class, you can manipulate the
  544. options for the select using:
  545. </para>
  546. <itemizedlist>
  547. <listitem>
  548. <para><methodname>addMultiOption($option, $value)</methodname></para>
  549. </listitem>
  550. <listitem>
  551. <para><methodname>addMultiOptions(array $options)</methodname></para>
  552. </listitem>
  553. <listitem>
  554. <para>
  555. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  556. options)
  557. </para>
  558. </listitem>
  559. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  560. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  561. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  562. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  563. </itemizedlist>
  564. <para>
  565. If a translation adapter is registered with the form and/or element,
  566. option values will be translated for display purposes.
  567. </para>
  568. <para>
  569. By default, this element registers an <classname>InArray</classname> validator
  570. which validates against the array keys of registered options. You
  571. can disable this behavior by either calling
  572. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  573. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  574. configuration key.
  575. </para>
  576. </sect2>
  577. <sect2 id="zend.form.standardElements.password">
  578. <title>Zend_Form_Element_Password</title>
  579. <para>
  580. Password elements are basically normal text elements -- except that
  581. you typically do not want the submitted password displayed in error
  582. messages or the element itself when the form is re-displayed.
  583. </para>
  584. <para>
  585. <classname>Zend_Form_Element_Password</classname> achieves this by calling
  586. <methodname>setObscureValue(true)</methodname> on each validator (ensuring that
  587. the password is obscured in validation error messages), and using
  588. the 'formPassword' view helper (which does not display the value
  589. passed to it).
  590. </para>
  591. </sect2>
  592. <sect2 id="zend.form.standardElements.radio">
  593. <title>Zend_Form_Element_Radio</title>
  594. <para>
  595. Radio elements allow you to specify several options, of which you
  596. need a single value returned. <classname>Zend_Form_Element_Radio</classname>
  597. extends the base <classname>Zend_Form_Element_Multi</classname> class,
  598. allowing you to specify a number of options, and then uses the
  599. <emphasis>formRadio</emphasis> view helper to display these.
  600. </para>
  601. <para>
  602. By default, this element registers an <classname>InArray</classname> validator
  603. which validates against the array keys of registered options. You
  604. can disable this behavior by either calling
  605. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  606. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  607. configuration key.
  608. </para>
  609. <para>
  610. Like all elements extending the Multi element base class, the
  611. following methods may be used to manipulate the radio options
  612. displayed:
  613. </para>
  614. <itemizedlist>
  615. <listitem>
  616. <para><methodname>addMultiOption($option, $value)</methodname></para>
  617. </listitem>
  618. <listitem>
  619. <para><methodname>addMultiOptions(array $options)</methodname></para>
  620. </listitem>
  621. <listitem>
  622. <para>
  623. <methodname>setMultiOptions(array $options)</methodname>
  624. (overwrites existing options)
  625. </para>
  626. </listitem>
  627. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  628. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  629. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  630. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  631. </itemizedlist>
  632. </sect2>
  633. <sect2 id="zend.form.standardElements.reset">
  634. <title>Zend_Form_Element_Reset</title>
  635. <para>
  636. Reset buttons are typically used to clear a form, and are not part
  637. of submitted data. However, as they serve a purpose in the display,
  638. they are included in the standard elements.
  639. </para>
  640. <para>
  641. <classname>Zend_Form_Element_Reset</classname> extends <link
  642. linkend="zend.form.standardElements.submit">Zend_Form_Element_Submit</link>.
  643. As such, the label is used for the button display, and will be
  644. translated if a translation adapter is present. It utilizes only the
  645. 'ViewHelper' and 'DtDdWrapper' decorators, as there should never be
  646. error messages for such elements, nor will a label be necessary.
  647. </para>
  648. </sect2>
  649. <sect2 id="zend.form.standardElements.select">
  650. <title>Zend_Form_Element_Select</title>
  651. <para>
  652. Select boxes are a common way of limiting to specific choices for a
  653. given form datum. <classname>Zend_Form_Element_Select</classname> allows you
  654. to generate these quickly and easily.
  655. </para>
  656. <para>
  657. By default, this element registers an <classname>InArray</classname> validator
  658. which validates against the array keys of registered options. You
  659. can disable this behavior by either calling
  660. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  661. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  662. configuration key.
  663. </para>
  664. <para>
  665. As it extends the base Multi element, the following methods may be
  666. used to manipulate the select options:
  667. </para>
  668. <itemizedlist>
  669. <listitem>
  670. <para><methodname>addMultiOption($option, $value)</methodname></para>
  671. </listitem>
  672. <listitem>
  673. <para><methodname>addMultiOptions(array $options)</methodname></para>
  674. </listitem>
  675. <listitem>
  676. <para>
  677. <methodname>setMultiOptions(array $options)</methodname>
  678. (overwrites existing options)
  679. </para>
  680. </listitem>
  681. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  682. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  683. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  684. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  685. </itemizedlist>
  686. <para>
  687. <classname>Zend_Form_Element_Select</classname> uses the 'formSelect' view
  688. helper for decoration.
  689. </para>
  690. </sect2>
  691. <sect2 id="zend.form.standardElements.submit">
  692. <title>Zend_Form_Element_Submit</title>
  693. <para>
  694. Submit buttons are used to submit a form. You may use multiple
  695. submit buttons; you can use the button used to submit the form to
  696. decide what action to take with the data submitted.
  697. <classname>Zend_Form_Element_Submit</classname> makes this decisioning easy,
  698. by adding a <methodname>isChecked()</methodname> method; as only one button
  699. element will be submitted by the form, after populating or
  700. validating the form, you can call this method on each submit button
  701. to determine which one was used.
  702. </para>
  703. <para>
  704. <classname>Zend_Form_Element_Submit</classname> uses the label as the "value"
  705. of the submit button, translating it if a translation adapter is
  706. present. <methodname>isChecked()</methodname> checks the submitted value against
  707. the label in order to determine if the button was used.
  708. </para>
  709. <para>
  710. The <link
  711. linkend="zend.form.standardDecorators.viewHelper">ViewHelper</link>
  712. and <link
  713. linkend="zend.form.standardDecorators.dtDdWrapper">DtDdWrapper</link>
  714. decorators to render the element. No label decorator is used, as the
  715. button label is used when rendering the element; also, typically,
  716. you will not associate errors with a submit element.
  717. </para>
  718. </sect2>
  719. <sect2 id="zend.form.standardElements.text">
  720. <title>Zend_Form_Element_Text</title>
  721. <para>
  722. By far the most prevalent type of form element is the text element,
  723. allowing for limited text entry; it's an ideal element for most data
  724. entry. <classname>Zend_Form_Element_Text</classname> simply uses the
  725. 'formText' view helper to display the element.
  726. </para>
  727. </sect2>
  728. <sect2 id="zend.form.standardElements.textarea">
  729. <title>Zend_Form_Element_Textarea</title>
  730. <para>
  731. Textareas are used when large quantities of text are expected, and
  732. place no limits on the amount of text submitted (other than maximum
  733. size limits as dictated by your server or <acronym>PHP</acronym>).
  734. <classname>Zend_Form_Element_Textarea</classname> uses the 'textArea' view
  735. helper to display such elements, placing the value as the content of
  736. the element.
  737. </para>
  738. </sect2>
  739. </sect1>
  740. <!--
  741. vim:se ts=4 sw=4 tw=80 et:
  742. -->