| 24 | | /* |
|---|
| 25 | | # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container |
|---|
| 26 | | # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and |
|---|
| 27 | | # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values |
|---|
| 28 | | # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +Selected+ |
|---|
| 29 | | # may also be an array of values to be selected when using a multiple select. |
|---|
| 30 | | # |
|---|
| 31 | | # Examples (call, result): |
|---|
| 32 | | # options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) |
|---|
| 33 | | # <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> |
|---|
| 34 | | # |
|---|
| 35 | | # options_for_select([ "VISA", "MasterCard" ], "MasterCard") |
|---|
| 36 | | # <option>VISA</option>\n<option selected="selected">MasterCard</option> |
|---|
| 37 | | # |
|---|
| 38 | | # options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") |
|---|
| 39 | | # <option value="$20">Basic</option>\n<option value="$40" selected="selected">Plus</option> |
|---|
| 40 | | # |
|---|
| 41 | | # options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"]) |
|---|
| 42 | | # <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option> |
|---|
| 43 | | # |
|---|
| 44 | | # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. |
|---|
| | 24 | /** |
|---|
| | 25 | * Returns a formatted set of <option> tags based on optional <i>$options</i> array variable. |
|---|
| | 26 | * |
|---|
| | 27 | * The options_for_select helper is usually called in conjunction with the select_tag helper, as it is relatively |
|---|
| | 28 | * useless on its own. By passing an array of <i>$options</i>, the helper will automatically generate <option> tags |
|---|
| | 29 | * using the array key as the value and the array value as the display title. Additionally the options_for_select tag is |
|---|
| | 30 | * smart enough to detect nested arrays as <optgroup> tags. If the helper detects that the array value is an array itself, |
|---|
| | 31 | * it creates an <optgroup> tag with the name of the group being the key and the contents of the <optgroup> being the array. |
|---|
| | 32 | * |
|---|
| | 33 | * <b>Options:</b> |
|---|
| | 34 | * - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value |
|---|
| | 35 | * - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value |
|---|
| | 36 | * |
|---|
| | 37 | * <b>Examples:</b> |
|---|
| | 38 | * <code> |
|---|
| | 39 | * echo select_tag('person', options_for_select(array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly'))); |
|---|
| | 40 | * </code> |
|---|
| | 41 | * |
|---|
| | 42 | * <code> |
|---|
| | 43 | * $card_list = array('VISA' => 'Visa', 'MAST' => 'MasterCard', 'AMEX' => 'American Express', 'DISC' => 'Discover'); |
|---|
| | 44 | * echo select_tag('cc_type', options_for_select($card_list), 'AMEX', array('include_custom' => '-- Select Credit Card Type --')); |
|---|
| | 45 | * </code> |
|---|
| | 46 | * |
|---|
| | 47 | * <code> |
|---|
| | 48 | * $optgroup_array = array(1 => 'Joe', 2 => 'Sue', 'Group A' => array(3 => 'Mary', 4 => 'Tom'), 'Group B' => array(5 => 'Bill', 6 =>'Andy')); |
|---|
| | 49 | * echo select_tag('employee', options_for_select($optgroup_array, null, array('include_blank' => true)), array('class' => 'mystyle')); |
|---|
| | 50 | * </code> |
|---|
| | 51 | * |
|---|
| | 52 | * @param array dataset to create <option> tags and <optgroup> tags from |
|---|
| | 53 | * @param string selected option value |
|---|
| | 54 | * @param array additional HTML compliant <option> tag parameters |
|---|
| | 55 | * @return string populated with <option> tags derived from the <i>$options</i> array variable |
|---|
| | 56 | * @see select_tag |
|---|
| 98 | | /* |
|---|
| 99 | | # Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like |
|---|
| 100 | | # ActionController::Base#url_for. The method for the form defaults to POST. |
|---|
| 101 | | # |
|---|
| 102 | | # Options: |
|---|
| 103 | | # * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data". |
|---|
| | 110 | /** |
|---|
| | 111 | * Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>. |
|---|
| | 112 | * |
|---|
| | 113 | * By default, the form tag is generated in POST format, but can easily be configured along with any additional |
|---|
| | 114 | * HTML parameters via the optional <i>$options</i> variable. If you are using file uploads, be sure to set the |
|---|
| | 115 | * <i>multipart</i> option to true. |
|---|
| | 116 | * |
|---|
| | 117 | * <b>Options:</b> |
|---|
| | 118 | * - multipart - When set to true, enctype is set to "multipart/form-data". |
|---|
| | 119 | * |
|---|
| | 120 | * <b>Examples:</b> |
|---|
| | 121 | * <code><?php echo form_tag('@myroute'); ?></code> |
|---|
| | 122 | * <code><?php echo form_tag('/module/action', array('name' => 'myformname', 'multipart' => true)); ?></code> |
|---|
| | 123 | * |
|---|
| | 124 | * @param string valid action, route or URL |
|---|
| | 125 | * @param array optional HTML parameters for the <form> tag |
|---|
| | 126 | * @return string opening HTML <form> tag with options |
|---|
| | 149 | /** |
|---|
| | 150 | * Returns a <select> tag, optionally comprised of <option> tags. |
|---|
| | 151 | * |
|---|
| | 152 | * The select tag does not generate <option> tags by default. |
|---|
| | 153 | * To do so, you must populate the <i>$option_tags</i> variable with a string of valid HTML compliant <option> tags. |
|---|
| | 154 | * Fortunately, Symfony provides a handy helper function to convert an array of data into option tags (see options_for_select). |
|---|
| | 155 | * If you need to create a "multiple" select tag (ability to select multiple options), set the <i>multiple</i> option to true. |
|---|
| | 156 | * Doing so will automatically convert the name field to an array type variable (i.e. name="name" becomes name="name[]"). |
|---|
| | 157 | * |
|---|
| | 158 | * <b>Options:</b> |
|---|
| | 159 | * - multiple - If set to true, the select tag will allow multiple options to be selected at once. |
|---|
| | 160 | * |
|---|
| | 161 | * <b>Examples:</b> |
|---|
| | 162 | * <code> |
|---|
| | 163 | * $person_list = array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly'); |
|---|
| | 164 | * echo select_tag('person', options_for_select($person_list, $sf_params->get('person')), array('class' => 'full')); |
|---|
| | 165 | * </code> |
|---|
| | 166 | * |
|---|
| | 167 | * <code> |
|---|
| | 168 | * echo select_tag('department', options_for_select($department_list), array('multiple' => true)); |
|---|
| | 169 | * </code> |
|---|
| | 170 | * |
|---|
| | 171 | * <code> |
|---|
| | 172 | * echo select_tag('url', options_for_select($url_list), array('onChange' => 'Javascript:this.form.submit();')); |
|---|
| | 173 | * </code> |
|---|
| | 174 | * |
|---|
| | 175 | * @param string field name |
|---|
| | 176 | * @param string contains a string of valid <option></option> tags |
|---|
| | 177 | * @param array additional HTML compliant <select> tag parameters |
|---|
| | 178 | * @return string <select> tag optionally comprised of <option> tags. |
|---|
| | 179 | * @see options_for_select, content_tag |
|---|
| | 180 | */ |
|---|
| | 193 | /** |
|---|
| | 194 | * Returns a <select> tag populated with all the countries in the world. |
|---|
| | 195 | * |
|---|
| | 196 | * The select_country_tag builds off the traditional select_tag function, and is conveniently populated with |
|---|
| | 197 | * all the countries in the world (sorted alphabetically). Each option in the list has a two-character country |
|---|
| | 198 | * code for its value and the country's name as its display title. The country data is retrieved via the sfCultureInfo |
|---|
| | 199 | * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world. |
|---|
| | 200 | * Here's an example of an <option> tag generated by the select_country_tag: |
|---|
| | 201 | * |
|---|
| | 202 | * <samp> |
|---|
| | 203 | * <option value="US">United States</option> |
|---|
| | 204 | * </samp> |
|---|
| | 205 | * |
|---|
| | 206 | * <b>Examples:</b> |
|---|
| | 207 | * <code> |
|---|
| | 208 | * echo select_country_tag('country', 'FR'); |
|---|
| | 209 | * </code> |
|---|
| | 210 | * |
|---|
| | 211 | * @param string field name |
|---|
| | 212 | * @param string selected field value (two-character country code) |
|---|
| | 213 | * @param array additional HTML compliant <select> tag parameters |
|---|
| | 214 | * @return string <select> tag populated with all the countries in the world. |
|---|
| | 215 | * @see select_tag, options_for_select, sfCultureInfo |
|---|
| | 216 | */ |
|---|
| | 240 | /** |
|---|
| | 241 | * Returns a <select> tag populated with all the languages in the world (or almost). |
|---|
| | 242 | * |
|---|
| | 243 | * The select_language_tag builds off the traditional select_tag function, and is conveniently populated with |
|---|
| | 244 | * all the languages in the world (sorted alphabetically). Each option in the list has a two or three character |
|---|
| | 245 | * language/culture code for its value and the language's name as its display title. The country data is |
|---|
| | 246 | * retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various |
|---|
| | 247 | * countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_country_tag: |
|---|
| | 248 | * |
|---|
| | 249 | * <samp> |
|---|
| | 250 | * <option value="en">English</option> |
|---|
| | 251 | * </samp> |
|---|
| | 252 | * |
|---|
| | 253 | * <b>Examples:</b> |
|---|
| | 254 | * <code> |
|---|
| | 255 | * echo select_language_tag('language', 'de'); |
|---|
| | 256 | * </code> |
|---|
| | 257 | * |
|---|
| | 258 | * @param string field name |
|---|
| | 259 | * @param string selected field value (two or threecharacter language/culture code) |
|---|
| | 260 | * @param array additional HTML compliant <select> tag parameters |
|---|
| | 261 | * @return string <select> tag populated with all the languages in the world. |
|---|
| | 262 | * @see select_tag, options_for_select, sfCultureInfo |
|---|
| | 263 | */ |
|---|
| | 337 | /** |
|---|
| | 338 | * Returns an XHTML compliant <input> tag with type="file". |
|---|
| | 339 | * |
|---|
| | 340 | * Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML <input> tag and can utilize |
|---|
| | 341 | * any standard <input> tag parameters passed in the optional <i>$options</i> variable. The only difference is that it |
|---|
| | 342 | * creates the tag with type="file", meaning that next to the field will be a "browse" (or similar) button. |
|---|
| | 343 | * This gives the user the ability to choose a file from there computer to upload to the web server. Remember, if you |
|---|
| | 344 | * plan to upload files to your website, be sure to set the <i>multipart</i> option form_tag helper function to true |
|---|
| | 345 | * or your files will not be properly uploaded to the web server. |
|---|
| | 346 | * |
|---|
| | 347 | * <b>Examples:</b> |
|---|
| | 348 | * <code> |
|---|
| | 349 | * echo input_file_tag('filename', array('size' => 30)); |
|---|
| | 350 | * </code> |
|---|
| | 351 | * |
|---|
| | 352 | * @param string field name |
|---|
| | 353 | * @param array additional HTML compliant <input> tag parameters |
|---|
| | 354 | * @return string XHTML compliant <input> tag with type="file" |
|---|
| | 355 | * @see input_tag, form_tag |
|---|
| | 356 | */ |
|---|
| | 365 | /** |
|---|
| | 366 | * Returns an XHTML compliant <input> tag with type="password". |
|---|
| | 367 | * |
|---|
| | 368 | * Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML <input> tag and can utilize |
|---|
| | 369 | * any standard <input> tag parameters passed in the optional <i>$options</i> variable. The only difference is that it |
|---|
| | 370 | * creates the tag with type="password", meaning that the text entered into this field will not be visible to the end user. |
|---|
| | 371 | * In most cases it is replaced by ********. Even though this text is not readable, it is recommended that you do not |
|---|
| | 372 | * populate the optional <i>$value</i> option with a plain-text password or any other sensitive information, as this is a |
|---|
| | 373 | * potential security risk. |
|---|
| | 374 | * |
|---|
| | 375 | * <b>Examples:</b> |
|---|
| | 376 | * <code> |
|---|
| | 377 | * echo input_password_tag('password'); |
|---|
| | 378 | * echo input_password_tag('password_confirm'); |
|---|
| | 379 | * </code> |
|---|
| | 380 | * |
|---|
| | 381 | * @param string field name |
|---|
| | 382 | * @param string populated field value |
|---|
| | 383 | * @param array additional HTML compliant <input> tag parameters |
|---|
| | 384 | * @return string XHTML compliant <input> tag with type="password" |
|---|
| | 385 | * @see input_tag |
|---|
| | 386 | */ |
|---|