symfony API

FormHelper Functions

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.1 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.1 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

FormHelper.

Function Summary

  • string checkbox_tag($name, $value, $checked, $options)
    Returns an XHTML compliant <input> tag with type="checkbox".
  • string form_tag($url_for_options, $options)
    Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>.
  • string input_date_range_tag($name, $value, $options)
    Returns two XHTML compliant <input> tags to be used as a free-text date fields for a date range.
  • string input_date_tag($name, $value, $options)
    Returns an XHTML compliant <input> tag to be used as a free-text date field.
  • string input_file_tag($name, $options)
    Returns an XHTML compliant <input> tag with type="file".
  • string input_hidden_tag($name, $value, $options)
    Returns an XHTML compliant <input> tag with type="hidden".
  • string input_password_tag($name, $value, $options)
    Returns an XHTML compliant <input> tag with type="password".
  • string input_tag($name, $value, $options)
    Returns an XHTML compliant <input> tag with type="text".
  • string label_for($id, $label, $options)
    Returns a <label> tag with <i>$label</i> for the specified <i>$id</i> parameter.
  • string options_for_select($options, $selected, $html_options)
    Returns a formatted set of <option> tags based on optional <i>$options</i> array variable.
  • string radiobutton_tag($name, $value, $checked, $options)
    Returns an XHTML compliant <input> tag with type="radio".
  • string reset_tag($name, $options)
    Returns an XHTML compliant <input> tag with type="reset".
  • string select_country_tag($name, $selected, $options)
    Returns a <select> tag populated with all the countries in the world.
  • string select_currency_tag($name, $selected, $options)
    Returns a <select> tag populated with all the currencies in the world (or almost).
  • string select_language_tag($name, $selected, $options)
    Returns a <select> tag populated with all the languages in the world (or almost).
  • string select_tag($name, $option_tags, $options)
    Returns a <select> tag, optionally comprised of <option> tags.
  • string submit_image_tag($source, $options)
    Returns an XHTML compliant <input> tag with type="image".
  • string submit_tag($name, $options)
    Returns an XHTML compliant <input> tag with type="submit".
  • string textarea_tag($name, $content, $options)
    Returns a <textarea> tag, optionally wrapped with an inline rich-text JavaScript editor.
  • _convert_include_custom_for_select()

Function Details

  • (string) checkbox_tag ($name, $value, $checked, $options) Browse code

    $name field name
    $value checkbox value (if checked)
    $checked is the checkbox checked? (1 or 0)
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="checkbox".


    When creating multiple checkboxes with the same name, be sure to use an array for the
    $name parameter (i.e. 'name[]'). The checkbox_tag is smart enough to create unique ID's
    based on the $value parameter like so:






    Examples:

    echo checkbox_tag('newsletter', 1, $sf_params->get('newsletter'));


    echo checkbox_tag('option_a', 'yes', true, array('class' => 'style_a'));


    // one request variable with an array of checkbox values
    echo checkbox_tag('choice[]', 1);
    echo checkbox_tag('choice[]', 2);
    echo checkbox_tag('choice[]', 3);
    echo checkbox_tag('choice[]', 4);


    // assuming you have Prototype.js enabled, you could do this
    echo checkbox_tag('show_tos', 1, false, array('onclick' => "Element.toggle('tos'); return false;"));

    returns XHTML compliant tag with type="checkbox"

  • (string) form_tag ($url_for_options, $options) Browse code

    $url_for_options valid action, route or URL
    $options optional HTML parameters for the
    tag

    Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>.


    By default, the form tag is generated in POST format, but can easily be configured along with any additional
    HTML parameters via the optional $options parameter. If you are using file uploads, be sure to set the
    multipart option to true.

    Options:
    - multipart - When set to true, enctype is set to "multipart/form-data".

    Examples:

    'myformname', 'multipart' => true)); ?>

    returns opening HTML tag with options

  • (string) input_date_range_tag ($name, $value, $options) Browse code

    $name field name
    $value dates: $value['from'] and $value['to']
    $options additional HTML compliant tag parameters

    Returns two XHTML compliant <input> tags to be used as a free-text date fields for a date range.


    Built on the input_date_tag, the input_date_range_tag combines two input tags that allow the user
    to specify a from and to date.
    You can easily implement a JavaScript calendar by enabling the 'rich' option in the
    $options parameter. This includes a button next to the field that when clicked,
    will open an inline JavaScript calendar. When a date is selected, it will automatically
    populate the tag with the proper date, formatted to the user's culture setting.

    Note: The $name parameter will automatically converted to array names.
    For example, a $name of "date" becomes date[from] and date[to]

    Options:
    - rich - If set to true, includes an inline JavaScript calendar can auto-populate the date field with the chosen date
    - before - string to be displayed before the input_date_range_tag
    - middle - string to be displayed between the from and to tags
    - after - string to be displayed after the input_date_range_tag

    Examples:

    $date = array('from' => '2006-05-15', 'to' => '2006-06-15');
    echo input_date_range_tag('date', $date, array('rich' => true));


    echo input_date_range_tag('date', null, array('middle' => ' through ', 'rich' => true));

    returns XHTML compliant tag with optional JS calendar integration

  • (string) input_date_tag ($name, $value, $options) Browse code

    $name field name
    $value date
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag to be used as a free-text date field.


    You can easily implement a JavaScript calendar by enabling the 'rich' option in the
    $options parameter. This includes a button next to the field that when clicked,
    will open an inline JavaScript calendar. When a date is selected, it will automatically
    populate the tag with the proper date, formatted to the user's culture setting.
    Symfony also conveniently offers the input_date_range_tag, that allows you to specify a to
    and from date.

    Options:
    - rich - If set to true, includes an inline JavaScript calendar can auto-populate the date field with the chosen date

    Examples:

    echo input_date_tag('date', null, array('rich' => true));

    returns XHTML compliant tag with optional JS calendar integration

  • (string) input_file_tag ($name, $options) Browse code

    $name field name
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="file".


    Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML tag and can utilize
    any standard tag parameters passed in the optional $options parameter. The only difference is that it
    creates the tag with type="file", meaning that next to the field will be a "browse" (or similar) button.
    This gives the user the ability to choose a file from there computer to upload to the web server. Remember, if you
    plan to upload files to your website, be sure to set the multipart option form_tag helper function to true
    or your files will not be properly uploaded to the web server.

    Examples:

    echo input_file_tag('filename', array('size' => 30));

    returns XHTML compliant tag with type="file"

  • (string) input_hidden_tag ($name, $value, $options) Browse code

    $name field name
    $value populated field value
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="hidden".


    Similar to the input_tag helper, the input_hidden_tag helper generates an XHTML tag and can utilize
    any standard tag parameters passed in the optional $options parameter. The only difference is
    that it creates the tag with type="hidden", meaning that is not visible on the page.

    Examples:

    echo input_hidden_tag('id', $id);

    returns XHTML compliant tag with type="hidden"

  • (string) input_password_tag ($name, $value, $options) Browse code

    $name field name
    $value populated field value
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="password".


    Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML tag and can utilize
    any standard tag parameters passed in the optional $options parameter. The only difference is that it
    creates the tag with type="password", meaning that the text entered into this field will not be visible to the end user.
    In most cases it is replaced by * * * * * * * *. Even though this text is not readable, it is recommended that you do not
    populate the optional $value option with a plain-text password or any other sensitive information, as this is a
    potential security risk.

    Examples:

    echo input_password_tag('password');
    echo input_password_tag('password_confirm');

    returns XHTML compliant tag with type="password"

  • (string) input_tag ($name, $value, $options) Browse code

    $name field name
    $value selected field value
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="text".


    The input_tag helper generates your basic XHTML tag and can utilize any standard tag parameters
    passed in the optional $options parameter.

    Examples:

    echo input_tag('name');


    echo input_tag('amount', $sf_params->get('amount'), array('size' => 8, 'maxlength' => 8));

    returns XHTML compliant tag with type="text"

  • (string) label_for ($id, $label, $options) Browse code

    $id id
    $label label or title
    $options additional HTML compliant

    Returns a <label> tag with <i>$label</i> for the specified <i>$id</i> parameter.

    returns

  • (string) options_for_select ($options, $selected, $html_options) Browse code

    $options dataset to create tags from
    $selected selected option value
    $html_options additional HTML compliant

    Returns a formatted set of <option> tags based on optional <i>$options</i> array variable.


    The options_for_select helper is usually called in conjunction with the select_tag helper, as it is relatively
    useless on its own. By passing an array of $options, the helper will automatically generate tags. If the helper detects that the array value is an array itself,
    it creates an tag with the name of the group being the key and the contents of the being the array.

    Options:
    - include_blank - Includes a blank

    Examples:

    echo select_tag('person', options_for_select(array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly')));


    $card_list = array('VISA' => 'Visa', 'MAST' => 'MasterCard', 'AMEX' => 'American Express', 'DISC' => 'Discover');
    echo select_tag('cc_type', options_for_select($card_list, 'AMEX', array('include_custom' => '-- Select Credit Card Type --')));


    $optgroup_array = array(1 => 'Joe', 2 => 'Sue', 'Group A' => array(3 => 'Mary', 4 => 'Tom'), 'Group B' => array(5 => 'Bill', 6 =>'Andy'));
    echo select_tag('employee', options_for_select($optgroup_array, null, array('include_blank' => true)), array('class' => 'mystyle'));

    returns populated with

  • (string) radiobutton_tag ($name, $value, $checked, $options) Browse code

    $name field name
    $value radio button value (if selected)
    $checked is the radio button selected? (1 or 0)
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="radio".


    Examples:

    echo ' Yes '.radiobutton_tag('newsletter', 1);
    echo ' No '.radiobutton_tag('newsletter', 0);

    returns XHTML compliant tag with type="radio"

  • (string) reset_tag ($name, $options) Browse code

    $name field value (title of reset button)
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="reset".


    By default, this helper creates a submit tag with a name of reset. Also, the default
    $value parameter (title of the button) is set to "Reset" which can be easily overwritten
    by passing a $value parameter.

    Examples:

    echo reset_tag();


    echo reset_tag('Start Over');

    returns XHTML compliant tag with type="reset"

  • (string) select_country_tag ($name, $selected, $options) Browse code

    $name field name
    $selected selected field value (two-character country code)
    $options additional HTML compliant

    Returns a <select> tag populated with all the countries in the world.


    The select_country_tag builds off the traditional select_tag function, and is conveniently populated with
    all the countries in the world (sorted alphabetically). Each option in the list has a two-character country
    code for its value and the country's name as its display title. The country data is retrieved via the sfCultureInfo
    class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
    Here's an example of an



    Examples:

    echo select_country_tag('country', 'FR');


    echo select_country_tag('country', 'de', array('countries' => array('US','FR')));

    returns

    $name field name
    $selected selected field value (threecharacter currency code)
    $options additional HTML compliant

    Returns a <select> tag populated with all the currencies in the world (or almost).


    The select_currency_tag builds off the traditional select_tag function, and is conveniently populated with
    all the currencies in the world (sorted alphabetically). Each option in the list has a three character
    currency code for its value and the currency's name as its display title. The currency data is
    retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
    countries and cultures throughout the world. Here's an example of an



    Examples:

    echo select_currency_tag('currency', 'EUR');


    echo select_currency_tag('currency', 'EUR', array('currencies' => array('EUR', 'USD'), 'display' => 'symbol'));

    returns

    $name field name
    $selected selected field value (two or threecharacter language/culture code)
    $options additional HTML compliant

    Returns a <select> tag populated with all the languages in the world (or almost).


    The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
    all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
    language/culture code for its value and the language's name as its display title. The country data is
    retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
    countries and cultures throughout the world. Here's an example of an



    Examples:

    echo select_language_tag('language', 'de');


    echo select_language_tag('language', 'de', array('languages' => array('en','fr','fi')));

    returns

    $name field name
    $option_tags contains a string of valid tags, or an array of options that will be passed to options_for_select
    $options additional HTML compliant

    Returns a <select> tag, optionally comprised of <option> tags.


    The select tag does not generate

    Examples:

    $person_list = array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly');
    echo select_tag('person', options_for_select($person_list, $sf_params->get('person')), array('class' => 'full'));


    echo select_tag('department', options_for_select($department_list), array('multiple' => true));


    echo select_tag('url', options_for_select($url_list), array('onChange' => 'Javascript:this.form.submit();'));

    returns

    $source path to image file
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="image".


    The submit_image_tag is very similar to the submit_tag, the only difference being that it uses an image
    for the submit button instead of the browser-generated default button. The image is defined by the
    $source parameter and must be a valid image, either local or remote (URL). By default, this
    helper creates a submit tag with a name of commit to avoid conflicts with other parts of the
    framework. It is recommended that you do not use the name "submit" for submit tags unless absolutely necessary.

    Examples:

    // Assuming your image is in the /web/images/ directory
    echo submit_image_tag('my_submit_button.gif');


    echo submit_image_tag('http://mydomain.com/my_submit_button.gif');

    returns XHTML compliant tag with type="image"

  • (string) submit_tag ($name, $options) Browse code

    $name field value (title of submit button)
    $options additional HTML compliant tag parameters

    Returns an XHTML compliant <input> tag with type="submit".


    By default, this helper creates a submit tag with a name of commit to avoid
    conflicts with other parts of the framework. It is recommended that you do not use the name
    "submit" for submit tags unless absolutely necessary. Also, the default $value parameter
    (title of the button) is set to "Save changes", which can be easily overwritten by passing a
    $value parameter.

    Examples:

    echo submit_tag();


    echo submit_tag('Update Record');

    returns XHTML compliant tag with type="submit"

  • (string) textarea_tag ($name, $content, $options) Browse code

    $name field name
    $content populated field value
    $options additional HTML compliant