2
0

Zend_Form-StandardElements.xml 32 KB

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