Zend_Form-StandardElements.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. </note>
  238. <para>
  239. Per default the file will automatically be received when you call
  240. <methodname>getValues()</methodname> on the form. The reason behind this behaviour is,
  241. that the file itself is the value of the file element.
  242. </para>
  243. <programlisting language="php"><![CDATA[
  244. $form->getValues();
  245. ]]></programlisting>
  246. <note>
  247. <para>
  248. Therefor another call of <methodname>receive()</methodname> after calling
  249. <methodname>getValues()</methodname> will not have an effect. Also creating a
  250. instance of <classname>Zend_File_Transfer</classname> will not have an effect as
  251. there no file anymore to receive.
  252. </para>
  253. </note>
  254. <para>
  255. Still, sometimes you may want to call <methodname>getValues()</methodname> without
  256. receiving the file. You can archive this by calling
  257. <methodname>setValueDisabled(true)</methodname>. To get the actual value of this flag
  258. you can call <methodname>isValueDisabled()</methodname>.
  259. </para>
  260. <example id="zend.form.standardElements.file.retrievement">
  261. <title>Explicit file retrievement</title>
  262. <para>
  263. First call <methodname>setValueDisabled(true)</methodname>.
  264. </para>
  265. <programlisting language="php"><![CDATA[
  266. $element = new Zend_Form_Element_File('foo');
  267. $element->setLabel('Upload an image:')
  268. ->setDestination('/var/www/upload')
  269. ->setValueDisabled(true);
  270. ]]></programlisting>
  271. <para>
  272. Now the file will not be received when you call
  273. <methodname>getValues()</methodname>. So you must call
  274. <methodname>receive()</methodname> on the file element, or an instance of
  275. <classname>Zend_File_Transfer</classname> yourself.
  276. </para>
  277. <programlisting language="php"><![CDATA[
  278. $values = $form->getValues();
  279. if ($form->isValid($form->getPost())) {
  280. if (!$form->foo->receive()) {
  281. print "Upload error";
  282. }
  283. }
  284. ]]></programlisting>
  285. </example>
  286. <para>
  287. There are several states of the uploaded file which can be checked
  288. with the following methods:
  289. </para>
  290. <itemizedlist>
  291. <listitem>
  292. <para>
  293. <methodname>isUploaded()</methodname>: Checks if the file element has
  294. been uploaded or not.
  295. </para>
  296. </listitem>
  297. <listitem>
  298. <para>
  299. <methodname>isReceived()</methodname>: Checks if the file element has
  300. already been received.
  301. </para>
  302. </listitem>
  303. <listitem>
  304. <para>
  305. <methodname>isFiltered()</methodname>: Checks if the filters have already
  306. been applied to the file element or not.
  307. </para>
  308. </listitem>
  309. </itemizedlist>
  310. <example id="zend.form.standardElements.file.isuploaded">
  311. <title>Checking if an optional file has been uploaded</title>
  312. <programlisting language="php"><![CDATA[
  313. $element = new Zend_Form_Element_File('foo');
  314. $element->setLabel('Upload an image:')
  315. ->setDestination('/var/www/upload')
  316. ->setRequired(false);
  317. $element->addValidator('Size', false, 102400);
  318. $form->addElement($element, 'foo');
  319. // The foo file element is optional but when it's given go into here
  320. if ($form->foo->isUploaded()) {
  321. // foo file given... do something
  322. }
  323. ]]></programlisting>
  324. </example>
  325. <para>
  326. <classname>Zend_Form_Element_File</classname> also supports multiple files.
  327. By calling the <methodname>setMultiFile($count)</methodname> method you can set
  328. the number of file elements you want to create. This keeps you
  329. from setting the same settings multiple times.
  330. </para>
  331. <example id="zend.form.standardElements.file.multiusage">
  332. <title>Setting multiple files</title>
  333. <para>
  334. Creating a multifile element is the same as setting a single element.
  335. Just call <methodname>setMultiFile()</methodname> after the element is created:
  336. </para>
  337. <programlisting language="php"><![CDATA[
  338. $element = new Zend_Form_Element_File('foo');
  339. $element->setLabel('Upload an image:')
  340. ->setDestination('/var/www/upload');
  341. // ensure minimum 1, maximum 3 files
  342. $element->addValidator('Count', false, array('min' => 1, 'max' => 3));
  343. // limit to 100K
  344. $element->addValidator('Size', false, 102400);
  345. // only JPEG, PNG, and GIFs
  346. $element->addValidator('Extension', false, 'jpg,png,gif');
  347. // defines 3 identical file elements
  348. $element->setMultiFile(3);
  349. $form->addElement($element, 'foo');
  350. ]]></programlisting>
  351. <para>
  352. You now have 3 identical file upload elements
  353. with the same settings. To get the set multifile number simply call
  354. <methodname>getMultiFile()</methodname>.
  355. </para>
  356. </example>
  357. <note>
  358. <title>File elements in Subforms</title>
  359. <para>
  360. When you use file elements in subforms you must set unique names.
  361. For example, if you name a file element in subform1 "file", you must give
  362. any file element in subform2 a different name.
  363. </para>
  364. <para>
  365. If there are 2 file elements with the same name, the second
  366. element is not be displayed or submitted.
  367. </para>
  368. <para>
  369. Additionally, file elements are not rendered within the sub-form. So when
  370. you add a file element into a subform, then the element will be rendered
  371. within the main form.
  372. </para>
  373. </note>
  374. <para>
  375. To limit the size of the file uploaded, you can
  376. specify the maximum file size by setting the <constant>MAX_FILE_SIZE</constant>
  377. option on the form. When you set this value by using the
  378. <methodname>setMaxFileSize($size)</methodname> method, it will be rendered with the
  379. file element.
  380. </para>
  381. <programlisting language="php"><![CDATA[
  382. $element = new Zend_Form_Element_File('foo');
  383. $element->setLabel('Upload an image:')
  384. ->setDestination('/var/www/upload')
  385. ->addValidator('Size', false, 102400) // limit to 100K
  386. ->setMaxFileSize(102400); // limits the filesize on the client side
  387. $form->addElement($element, 'foo');
  388. ]]></programlisting>
  389. <note>
  390. <title>MaxFileSize with Multiple File Elements</title>
  391. <para>
  392. When you use multiple file elements in your form you should set
  393. the <constant>MAX_FILE_SIZE</constant> only once. Setting it again will
  394. overwrite the previous value.
  395. </para>
  396. <para>
  397. Note, that this is also the case when you use multiple forms.
  398. </para>
  399. </note>
  400. </sect2>
  401. <sect2 id="zend.form.standardElements.hidden">
  402. <title>Zend_Form_Element_Hidden</title>
  403. <para>
  404. Hidden elements inject data that should be submitted, but that should not manipulated by
  405. the user . <classname>Zend_Form_Element_Hidden</classname> accomplishes this with the
  406. 'formHidden' view helper.
  407. </para>
  408. </sect2>
  409. <sect2 id="zend.form.standardElements.hash">
  410. <title>Zend_Form_Element_Hash</title>
  411. <para>
  412. This element provides protection from CSRF attacks on forms,
  413. ensuring the data is submitted by the user session that generated
  414. the form and not by a rogue script. Protection is achieved by adding
  415. a hash element to a form and verifying it when the form is
  416. submitted.
  417. </para>
  418. <para>
  419. The name of the hash element should be unique. We recommend using
  420. the <literal>salt</literal> option for the element- two hashes with
  421. same names and different salts would not collide:
  422. </para>
  423. <programlisting language="php"><![CDATA[
  424. $form->addElement('hash', 'no_csrf_foo', array('salt' => 'unique'));
  425. ]]></programlisting>
  426. <para>
  427. You can set the salt later using the <methodname>setSalt($salt)</methodname>
  428. method.
  429. </para>
  430. <para>
  431. Internally, the element stores a unique identifier using
  432. <classname>Zend_Session_Namespace</classname>, and checks for it at
  433. submission (checking that the TTL has not expired). The 'Identical'
  434. validator is then used to ensure the submitted hash matches the
  435. stored hash.
  436. </para>
  437. <para>
  438. The 'formHidden' view helper is used to render the element in the
  439. form.
  440. </para>
  441. </sect2>
  442. <sect2 id="zend.form.standardElements.Image">
  443. <title>Zend_Form_Element_Image</title>
  444. <para>
  445. Images can be used as form elements, and you can use these images as
  446. graphical elements on form buttons.
  447. </para>
  448. <para>
  449. Images need an image source. <classname>Zend_Form_Element_Image</classname>
  450. allows you to specify this by using the <methodname>setImage()</methodname>
  451. accessor (or 'image' configuration key). You can also optionally specify a value to use
  452. when submitting the image using the <methodname>setImageValue()</methodname> accessor
  453. (or 'imageValue' configuration key). When the value set for the
  454. element matches the <property>imageValue</property>, then the accessor
  455. <methodname>isChecked()</methodname> will return <constant>TRUE</constant>.
  456. </para>
  457. <para>
  458. Image elements use the
  459. <link linkend="zend.form.standardDecorators.image">Image
  460. Decorator</link> for rendering, in addition to the standard Errors,
  461. HtmlTag, and Label decorators. You can optionally specify a tag to
  462. the <classname>Image</classname> decorator that will then wrap the image
  463. element.
  464. </para>
  465. </sect2>
  466. <sect2 id="zend.form.standardElements.multiCheckbox">
  467. <title>Zend_Form_Element_MultiCheckbox</title>
  468. <para>
  469. Often you have a set of related checkboxes, and you wish to group
  470. the results. This is much like a <link
  471. linkend="zend.form.standardElements.multiselect">Multiselect</link>,
  472. but instead of them being in a dropdown list, you need to show
  473. checkbox/value pairs.
  474. </para>
  475. <para>
  476. <classname>Zend_Form_Element_MultiCheckbox</classname> makes this a snap. Like
  477. all other elements extending the base Multi element, you can specify
  478. a list of options, and easily validate against that same list. The
  479. 'formMultiCheckbox' view helper ensures that these are returned as
  480. an array in the form submission.
  481. </para>
  482. <para>
  483. By default, this element registers an <classname>InArray</classname> validator
  484. which validates against the array keys of registered options. You
  485. can disable this behavior by either calling
  486. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  487. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  488. configuration key.
  489. </para>
  490. <para>
  491. You may manipulate the various checkbox options using the following
  492. methods:
  493. </para>
  494. <itemizedlist>
  495. <listitem>
  496. <para><methodname>addMultiOption($option, $value)</methodname></para>
  497. </listitem>
  498. <listitem>
  499. <para><methodname>addMultiOptions(array $options)</methodname></para>
  500. </listitem>
  501. <listitem>
  502. <para>
  503. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  504. options)
  505. </para>
  506. </listitem>
  507. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  508. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  509. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  510. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  511. </itemizedlist>
  512. <para>
  513. To mark checked items, you need to pass an array of values to
  514. <methodname>setValue()</methodname>. The following will check the values "bar"
  515. and "bat":
  516. </para>
  517. <programlisting language="php"><![CDATA[
  518. $element = new Zend_Form_Element_MultiCheckbox('foo', array(
  519. 'multiOptions' => array(
  520. 'foo' => 'Foo Option',
  521. 'bar' => 'Bar Option',
  522. 'baz' => 'Baz Option',
  523. 'bat' => 'Bat Option',
  524. );
  525. ));
  526. $element->setValue(array('bar', 'bat'));
  527. ]]></programlisting>
  528. <para>
  529. Note that even when setting a single value, you must pass an array.
  530. </para>
  531. </sect2>
  532. <sect2 id="zend.form.standardElements.multiselect">
  533. <title>Zend_Form_Element_Multiselect</title>
  534. <para>
  535. <acronym>XHTML</acronym> <emphasis>select</emphasis> elements allow a 'multiple'
  536. attribute, indicating multiple options may be selected for submission, instead
  537. of the usual one. <classname>Zend_Form_Element_Multiselect</classname> extends
  538. <link
  539. linkend="zend.form.standardElements.select">Zend_Form_Element_Select</link>,
  540. and sets the <property>multiple</property> attribute to 'multiple'. Like
  541. other classes that inherit from the base
  542. <classname>Zend_Form_Element_Multi</classname> class, you can manipulate the
  543. options for the select using:
  544. </para>
  545. <itemizedlist>
  546. <listitem>
  547. <para><methodname>addMultiOption($option, $value)</methodname></para>
  548. </listitem>
  549. <listitem>
  550. <para><methodname>addMultiOptions(array $options)</methodname></para>
  551. </listitem>
  552. <listitem>
  553. <para>
  554. <methodname>setMultiOptions(array $options)</methodname> (overwrites existing
  555. options)
  556. </para>
  557. </listitem>
  558. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  559. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  560. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  561. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  562. </itemizedlist>
  563. <para>
  564. If a translation adapter is registered with the form and/or element,
  565. option values will be translated for display purposes.
  566. </para>
  567. <para>
  568. By default, this element registers an <classname>InArray</classname> validator
  569. which validates against the array keys of registered options. You
  570. can disable this behavior by either calling
  571. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  572. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  573. configuration key.
  574. </para>
  575. </sect2>
  576. <sect2 id="zend.form.standardElements.password">
  577. <title>Zend_Form_Element_Password</title>
  578. <para>
  579. Password elements are basically normal text elements -- except that
  580. you typically do not want the submitted password displayed in error
  581. messages or the element itself when the form is re-displayed.
  582. </para>
  583. <para>
  584. <classname>Zend_Form_Element_Password</classname> achieves this by calling
  585. <methodname>setObscureValue(true)</methodname> on each validator (ensuring that
  586. the password is obscured in validation error messages), and using
  587. the 'formPassword' view helper (which does not display the value
  588. passed to it).
  589. </para>
  590. </sect2>
  591. <sect2 id="zend.form.standardElements.radio">
  592. <title>Zend_Form_Element_Radio</title>
  593. <para>
  594. Radio elements allow you to specify several options, of which you
  595. need a single value returned. <classname>Zend_Form_Element_Radio</classname>
  596. extends the base <classname>Zend_Form_Element_Multi</classname> class,
  597. allowing you to specify a number of options, and then uses the
  598. <emphasis>formRadio</emphasis> view helper to display these.
  599. </para>
  600. <para>
  601. By default, this element registers an <classname>InArray</classname> validator
  602. which validates against the array keys of registered options. You
  603. can disable this behavior by either calling
  604. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  605. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  606. configuration key.
  607. </para>
  608. <para>
  609. Like all elements extending the Multi element base class, the
  610. following methods may be used to manipulate the radio options
  611. displayed:
  612. </para>
  613. <itemizedlist>
  614. <listitem>
  615. <para><methodname>addMultiOption($option, $value)</methodname></para>
  616. </listitem>
  617. <listitem>
  618. <para><methodname>addMultiOptions(array $options)</methodname></para>
  619. </listitem>
  620. <listitem>
  621. <para>
  622. <methodname>setMultiOptions(array $options)</methodname>
  623. (overwrites existing options)
  624. </para>
  625. </listitem>
  626. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  627. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  628. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  629. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  630. </itemizedlist>
  631. </sect2>
  632. <sect2 id="zend.form.standardElements.reset">
  633. <title>Zend_Form_Element_Reset</title>
  634. <para>
  635. Reset buttons are typically used to clear a form, and are not part
  636. of submitted data. However, as they serve a purpose in the display,
  637. they are included in the standard elements.
  638. </para>
  639. <para>
  640. <classname>Zend_Form_Element_Reset</classname> extends <link
  641. linkend="zend.form.standardElements.submit">Zend_Form_Element_Submit</link>.
  642. As such, the label is used for the button display, and will be
  643. translated if a translation adapter is present. It utilizes only the
  644. 'ViewHelper' and 'DtDdWrapper' decorators, as there should never be
  645. error messages for such elements, nor will a label be necessary.
  646. </para>
  647. </sect2>
  648. <sect2 id="zend.form.standardElements.select">
  649. <title>Zend_Form_Element_Select</title>
  650. <para>
  651. Select boxes are a common way of limiting to specific choices for a
  652. given form datum. <classname>Zend_Form_Element_Select</classname> allows you
  653. to generate these quickly and easily.
  654. </para>
  655. <para>
  656. By default, this element registers an <classname>InArray</classname> validator
  657. which validates against the array keys of registered options. You
  658. can disable this behavior by either calling
  659. <methodname>setRegisterInArrayValidator(false)</methodname>, or by passing a
  660. <constant>FALSE</constant> value to the <property>registerInArrayValidator</property>
  661. configuration key.
  662. </para>
  663. <para>
  664. As it extends the base Multi element, the following methods may be
  665. used to manipulate the select options:
  666. </para>
  667. <itemizedlist>
  668. <listitem>
  669. <para><methodname>addMultiOption($option, $value)</methodname></para>
  670. </listitem>
  671. <listitem>
  672. <para><methodname>addMultiOptions(array $options)</methodname></para>
  673. </listitem>
  674. <listitem>
  675. <para>
  676. <methodname>setMultiOptions(array $options)</methodname>
  677. (overwrites existing options)
  678. </para>
  679. </listitem>
  680. <listitem><para><methodname>getMultiOption($option)</methodname></para></listitem>
  681. <listitem><para><methodname>getMultiOptions()</methodname></para></listitem>
  682. <listitem><para><methodname>removeMultiOption($option)</methodname></para></listitem>
  683. <listitem><para><methodname>clearMultiOptions()</methodname></para></listitem>
  684. </itemizedlist>
  685. <para>
  686. <classname>Zend_Form_Element_Select</classname> uses the 'formSelect' view
  687. helper for decoration.
  688. </para>
  689. </sect2>
  690. <sect2 id="zend.form.standardElements.submit">
  691. <title>Zend_Form_Element_Submit</title>
  692. <para>
  693. Submit buttons are used to submit a form. You may use multiple
  694. submit buttons; you can use the button used to submit the form to
  695. decide what action to take with the data submitted.
  696. <classname>Zend_Form_Element_Submit</classname> makes this decisioning easy,
  697. by adding a <methodname>isChecked()</methodname> method; as only one button
  698. element will be submitted by the form, after populating or
  699. validating the form, you can call this method on each submit button
  700. to determine which one was used.
  701. </para>
  702. <para>
  703. <classname>Zend_Form_Element_Submit</classname> uses the label as the "value"
  704. of the submit button, translating it if a translation adapter is
  705. present. <methodname>isChecked()</methodname> checks the submitted value against
  706. the label in order to determine if the button was used.
  707. </para>
  708. <para>
  709. The <link
  710. linkend="zend.form.standardDecorators.viewHelper">ViewHelper</link>
  711. and <link
  712. linkend="zend.form.standardDecorators.dtDdWrapper">DtDdWrapper</link>
  713. decorators to render the element. No label decorator is used, as the
  714. button label is used when rendering the element; also, typically,
  715. you will not associate errors with a submit element.
  716. </para>
  717. </sect2>
  718. <sect2 id="zend.form.standardElements.text">
  719. <title>Zend_Form_Element_Text</title>
  720. <para>
  721. By far the most prevalent type of form element is the text element,
  722. allowing for limited text entry; it's an ideal element for most data
  723. entry. <classname>Zend_Form_Element_Text</classname> simply uses the
  724. 'formText' view helper to display the element.
  725. </para>
  726. </sect2>
  727. <sect2 id="zend.form.standardElements.textarea">
  728. <title>Zend_Form_Element_Textarea</title>
  729. <para>
  730. Textareas are used when large quantities of text are expected, and
  731. place no limits on the amount of text submitted (other than maximum
  732. size limits as dictated by your server or <acronym>PHP</acronym>).
  733. <classname>Zend_Form_Element_Textarea</classname> uses the 'textArea' view
  734. helper to display such elements, placing the value as the content of
  735. the element.
  736. </para>
  737. </sect2>
  738. </sect1>
  739. <!--
  740. vim:se ts=4 sw=4 tw=80 et:
  741. -->