FUEL CMS User Guide : Version 1.5.2


Form Class

An alternative to the form_helper. This integrates with the FUEL Validator Object nicely to display errors with form elements.

The Form.php class is required if a form object is not passed in the initialization process.

Properties Reference

Property Default Value Description
public
attrs method="post" action="" Form html attributes
validator none
focus_highlight_cssclass field_highlight The focus css class
error_highlight_cssclass error_highlight The error highlight class

Function Reference [+]

$this->form->initialize([$params=array()])

Initialize preferences.

Returns

void

Parameters

(array) $params 

$this->form->set_validator('$validator')

Sets the validator object on the form object.

Returns

void

Parameters

(object) $validator validator object

$this->form->open(['$attrs'=NULL], ['$validator'=NULL])

Creates the opening form element.

Returns

string

Parameters

(mixed) $attrs attrs if array then create string
(object) $validator validator object

Example


	$validator = new Validator();
	echo $this->form->open('id="my_form"', $validator); 
	// will echo the following
	<form action="" method="post" id="my_form">
	

$this->form->open_multipart(['$attrs'=NULL], ['$validator'=NULL])

Creates the opening form element as a multipart.

Returns

string

Parameters

(mixed) $attrs attrs if array then create string
(object) $validator validator object

Example


	$validator = new Validator();
	echo $this->form->open_multipart('id="my_form"', $validator); 
	// will echo the following
	<form action="" method="post" id="my_form">
	

$this->form->close(['$html_before_form'=''], ['$add_csrf_field'=TRUE])

Creates the close form element as a multipart.

Returns

string

Parameters

(string) $html_before_form html to use before the closing form tag
(string) $add_csrf_field whether to include the csrf field before the closing tag

Example


	echo $this->form->close('<!--END OF FORM-->');
	// will echo the following
	<!--END OF FORM--></form>
	

$this->form->fieldset_open('$legend', ['$attrs'=NULL], ['$fieldset_id'=NULL])

Creates the opening fieldset element.

Returns

string

Parameters

(string) $legend legend name
(mixed) $attrs attrs if array then create string

Example


	echo $this->form->fieldset_open('MY Form Legend', 'id="my_legend"');
	// will echo the following
	<fieldset>
	<legend id="my_legend">MY Form Legend</legend>
	

$this->form->fieldset_close()

Creates the close fieldset element.

Returns

string

Example


	echo $this->form->fieldset_close();
	// will echo the following
	</fieldset>
	

$this->form->input('$name', ['$type'='text'], ['$value'=''], ['$attrs'=''])

Creates <input type="{text}"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $type type of input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	// will echo the following
	echo $this->form->input('email','text', 'dvader@deathstar.com', 'class="txt_field"');
	<input type="text" name="email" id="email" value="dvader@deathstar.com" class="txt_field" />
	

$this->form->text('$name', ['$value'=''], ['$attrs'=''])

Creates <input type="text"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->text('email', 'dvader@deathstar.com', 'class="txt_field"');
	// will echo the following
	<input type="text" name="email" id="email" value="dvader@deathstar.com" class="txt_field" />
	

$this->form->password('$name', ['$value'=''], ['$attrs'=''])

Creates <input type="password"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->hidden('password', 'abc134', 'class="txt_field"');
	// will echo the following
	<input type="passowrd" name="pwd" id="pwd"  value="" class="txt_field" />
	

Creates <input type="search"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->search('searh', 'Search...', 'class="txt_field"');
	// will echo the following
	<input type="searh" name="searh" id="searh" value="Search..." class="txt_field" />
	

$this->form->hidden('$name', ['$value'=''], ['$attrs'=''])

Creates <input type="hidden"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->hidden('id', '1', 'class="txt_field"');
	// will echo the following
	<input type="hidden" name="id" id="id" value="1" />
	

$this->form->radio('$name', ['$value'=''], ['$attrs'=''])

Creates <input type="radio"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->radio('yesno', 'yes', '');
	echo $this->form->radio('eitheror', 'no', '');

	// will echo the following
	<input type="radio" name="yesno" id="eitheror" value="yes" />
	<input type="radio" name="yesno" id="eitheror" value="no" />
	

$this->form->checkbox('$name', ['$value'=''], ['$attrs'=''])

Creates <input type="checkbox"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->checkbox('yesno', 'yes', '');
	// will echo the following
	<input type="checkbox" name="yesno" id="yesno" value="yes" />
	

$this->form->file('$name', ['$attrs'=''])

Creates <input type="file"> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $attrs value for the input element

Example


	echo $this->form->file('myfile', 'class="file_class"');
	// will echo the following
	<input type="file" name="myfile" id="myfile" value="" class="file_class" />
	

$this->form->select('$name', [$options=array()], ['$value'=''], ['$attrs'=''], ['$first_option'=''], [$disabled=array()])

Creates <select> tag.

Returns

string

Parameters

(string) $name name of the input element
(array) $options options for the form element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element
(string) $first_option the first option
(array) $disabled an array of disabled options

Example


	$options = array();
	$options['a'] = 'Option A';
	$options['b'] = 'Option B';
	$options['c'] = 'Option C';
	echo $this->form->select('my_options', $options, 'b', 'class="select_class"', 'Select one of these...');
	// will echo the following
	<select name="my_options" id="my_options" class="select_class">
		<option value="" label="Select one of these...">Select one of these...</option>
		<option value="a" label="A">A</option>
		<option value="b" label="B" selected="selected">B</option>
		<option value="b" label="C">C</option>
	</select>
	

$this->form->textarea('$name', ['$value'=''], ['$attrs'=''])

Creates <textarea> tag.

Returns

string

Parameters

(string) $name name of the input element
(string) $value value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->textarea('mytextfield', 'My text goes here.', 'class="txt_field"');
	// will echo the following
	<textarea name="mytextfield" id="mytextfield" class="txt_field">
	My text goes here.
	</textarea>
	

$this->form->submit('$value', ['$name'=''], ['$attrs'=''])

Creates <input type="submit"> tag.

Returns

string

Parameters

(string) $value name of the input element
(string) $name value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->submit('Submit', 'submit', 'class="submit"');
	// will echo the following
	<input type="submit" name="submit" id="submit" value="Submit" class="submit" />
	

$this->form->button('$value', ['$name'=''], ['$attrs'=''], ['$use_input_type'=TRUE])

Creates <input type="button"> tag.

Returns

string

Parameters

(string) $value name of the input element
(string) $name value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->button('mybutton', 'Click Me', 'class="btn"', FALSE);
	// will echo the following
	<button type="button" name="mybutton" id="mybutton" value="Click Me" class="btn" />mybutton</button>

	// with the last parameter as TRUE
	echo $this->form->button('mybutton', 'Click Me', 'class="btn"', TRUE);
	// will echo the following
	<input type="button" name="mybutton" id="mybutton" value="Click Me" class="btn" />
	

$this->form->reset('$value', ['$name'=''], ['$attrs'=''])

Creates <input type="reset"> tag.

Returns

string

Parameters

(string) $value name of the input element
(string) $name value for the input element
(mixed) $attrs html attributes for the input element

Example


	echo $this->form->reset('Reset', 'reset', 'class="reset_field"');
	// will echo the following
	<input type="reset" name="reset" id="reset" value="Reset" 'class="reset_field"' />
	

$this->form->image('$src', ['$name'=''], ['$value'=''], ['$attrs'=''])

Creates <input type="image"> tag.

Returns

string

Parameters

(string) $src src of the input element
(string) $name value for the input element
(mixed) $value html attributes for the input element

Example


	echo $this->form->image('assets/images/my_img.jpg', 'go_button', 'go', 'class="img_field"');
	// will echo the following
	<input type="image" src="assets/images/my_img.jpg" name="go_button" value="go" id="go_button" 'class="img_field"' />
	

$this->form->prep('$str', ['$double_encode'=TRUE])

A helper method to prepare string for textarea... taken from Kohana.

Returns

string

Parameters

(string) $str elements value

Example


	echo Form::prep('This will safely prep the form field text with entities like &amp; in it');
	// will echo the following
	This will safely prep the form field text with entities like &amp; in it
	

$this->form->do_checked('$val')

Checks a checkbox or radio.

Returns

string

Parameters

(string) $val elements value

Example


	$myval = (!empty($_POST['myval'])) ? $_POST['myval'] : '';
	echo $this->form->checkbox('mycheckbox', 'yes', Form::do_checked($myval=='yes'));
	// will echo the following
	<input type="checkbox" name="mycheckbox" id="mycheckbox" value="yes" checked="checked" />
	

$this->form->do_disabled('$val')

Sets disabled attribute of a form element.

Returns

string

Parameters

(string) $val elements value

Example


	$myval = (!empty($_POST['myval'])) ? $_POST['myval'] : '';
	echo $this->form->text('mytext', '', Form::do_disabled($myval==''));
	// will echo the following
	<input type="text" name="mytext" id="mytext" value="" disabled="disabled" />
	

$this->form->do_read_only('$val')

Sets read only attribute of a form element.

Returns

string

Parameters

(string) $val elements value

Example


	$myval = (!empty($_POST['myval'])) ? $_POST['myval'] : '';
	echo $this->form->text('mytext', '', Form::do_read_only($myval==''));
	// will echo the following
	<input type="text" name="mytext" id="mytext" value="" readonly="readonly" />
	

$this->form->create_id('$name')

Creates the id attribute for the field and label.

Returns

string

Parameters

(string) $name name of the field

Example


	echo Form::create_id('my_array_field[1]');
	// will echo the following
	my_array_field_1
	

$this->form->create_attrs('$attrs')

Creates form attributes.

Returns

string

Parameters

(mixed) $attrs attrs if array then create string