0% found this document useful (0 votes)
40 views

Symfony - Forms

This document discusses form helpers in the PHP5 MVC framework. It provides examples of how to generate various form elements like input tags, textareas, selects, and submit buttons. It also describes object form helpers that generate form elements bound to object attributes, and rich form helpers that enhance elements with features like date pickers and rich text editors.

Uploaded by

oanceacristian88
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Symfony - Forms

This document discusses form helpers in the PHP5 MVC framework. It provides examples of how to generate various form elements like input tags, textareas, selects, and submit buttons. It also describes object form helpers that generate form elements bound to object attributes, and rich form helpers that enhance elements with features like date pickers and rich text editors.

Uploaded by

oanceacristian88
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Open-Source PHP5 MVC Framework

Agile Development

Helpers
PART 2 - FORMS
FORM HELPERS Standard Helper FORM HELPERS FOR OBJECTS
<?php echo use_helper('Object’) ?>
FORM TAG
Add the object_ prefix in front of the name
form_tag($url, $options) of the form helpers to get the name of the
<?php echo form_tag('test/save', Array('method' => 'get', 'id' => 'myForm', 'class' => 'simpleForm'))?> related object form helper:
// options argument with the associative array syntax object_input_tag($parameters)
<?php echo form_tag('test/save', ‘method=get id=myForm class=simpleForm')?> object_textarea_tag($parameters)
// options argument with the string syntax object_checkbox_tag($parameters)
object_input_date_tag($parameters)
STANDARD FORM ELEMENTS objects_for_select($parameters)
object_select_tag($parameters)
label_for($id, $label, $options) object_select_country_tag($parameters)
Returns a <label> tag with for the specified parameter. object_select_language_tag($parameters)
input_tag ($name, $value=null, $options) object_input_hidden_tag ($parameters)
<?php echo input_tag('name', 'default value') ?> The $parameters (for all object helpers) are:
// will generate in HTML: <input type="text" name="name" id="name" value="default value" /> ($object, $method, $options, $default_value)

input_hidden_tag($name, $value, $options) E.g.1: the text input tag looks like:
<?php echo input_hidden_tag('name', 'value') ?> <?php echo object_input_tag($customer,
'getTelephone') ?>
input_password_tag ($name= 'password', $value=null, $options) // will generate in HTML
<?php echo input_password_tag('name', 'value') ?> <input type="text" name="getTelephone"
rich textarea_tag ($name, $content=null, $options) id="getTelephone" value="0123456789" />
...provided that
<?php echo textarea_tag('name', 'default content', 'size=10x20') ?>
$customer->getTelephone()= '0123456789'
// will generate in HTML:
<textarea name="name" id="name" rows="20" cols="10">default content</textarea> E.g.2: picture a form built to edit the data
checkbox_tag ($name, $value, $checked=false, $options) of an article. There is an easy way to get the
list of the author with the “related_class”:
<?php echo checkbox_tag('married', '1', true) ?>
<?php echo checkbox_tag('driverslicence', 'B', false) ?> object_select_tag($article, 'getAuthorId',
// will generate in HTML: 'related_class=Author')
<input type="checkbox" name="married" id="married" value="1" checked="checked" /> Symfony will use the ->toString() method of
<input type="checkbox" name="driverslicence" id="driverslicence" value="B" /> the Author class to display the names of the
authors in a list. If the method is undefined,
radiobutton_tag ($name, $value, $checked=false, $options)
the primary key (in the example, the id
<?php echo radiobutton_tag('status', 'value1', true) ?> column) of the Author table is used instead.
<?php echo radiobutton_tag('status', 'value2', false) ?>
// will generate in HTML: Other list options:
<input type="radio" name="status" value="value1" checked="checked" /> include_blank
<input type="radio" name="status" value="value2" /> to add a first empty line to the list
select_tag ($name, $option_tags=null, $options) object_select_tag($article, 'getAuthorId',
options_for_select ($options=array(), $selected= '', $html_options) ‘related_class=Author include_blank')
<?php echo select_tag('name', options_for_select(Array('0' => 'Steve', '1' => 'Bob', '2' => 'Albert', include_title
'3' => 'Ian'), 3)) ?> to add a title in the first line of the list
object_select_tag($article, 'getAuthorId',
input_file_tag ($name, $options) ‘related_class=Author include_title')
<?php echo input_file_tag('name') ?>
include_custom
submit_tag($value, $options) // submit button (as text) includes an <option> tag with a custom display
<?php echo submit_tag('Save') ?> text in the first line of the list
object_select_tag($article, 'getAuthorId',
submit_image_tag($source, $options) // submit button (as image) ‘related_class=Author include_custom=select')
<?php echo submit_image_tag('submit_img') ?>
// will generate in HTML: <input type="image" name="submit" src="/images/submit_img.png" />
input_upload_tag ($name, $options)
rich RICH FORM ELEMENTS
rich input_date_tag ($name, $value, $options)
reset_tag ($value= 'Reset', $options) <?php echo input_date_tag('dateofbirth',
rich select_country_tag ($name, $value, $options) ‘2005-05-03', 'rich=true') ?>
// will generate in HTML:
select_language_tag ($name, $value, $options)
// a text input tag together with a calendar widget
Returns a <select> tag populated with all the languages in the world (or almost).
<?php echo textarea_tag('name', 'default
select_day_tag ($name, $value, $options, $html_options) content', 'rich=true size=10x20')) ?>
select_month_tag ($name, $value, $options, $html_options) // will generate in HTML:
select_year_tag ($name, $value, $options, $html_option) // a rich text edition zone powered by TinyMCE
select_date_tag ($name, $value, $options, $html_options) <?php echo select_country_tag('country',
select_second_tag ($name, $value, $options, $html_options) ‘Albania') ?>
// will generate in HTML:
select_minute_tag ($name, $value, $options, $html_options)
<select name="country" id="country">
select_hour_tag ($name, $value, $options, $html_options) <option>Afghanistan</option>
select_ampm_tag ($name, $value, $options, $html_options) <option selected="selected">Albania</option>
<option>Algeria</option>
select_time_tag ($name, $value, $options, $html_options) <option>American Samoa</option>
select_datetime_tag ($name, $value, $options, $html_options) ...

http://andreiabohner.wordpress.com This cheat-sheet is not an official part of the symfony documentation

You might also like