simpleAdminPlus v1.0

simpleAdminPlus Form

Click on a function to expand it.

form_for() $simpleAdmin->form->form_for()
form_for() – Initializes the form functions.

Usage

$simpleAdmin->form->form_for( [table_name], [row_id], [column_name] )
table_name string (required)
The name of the table to build the form for.
row_id integer, string or array (default=null)
If you are editing a row in your table, then supply the id or title of that row.
If you want to autofill some of the values then use an array.
column_name string (default=id)
The column name to get the row's data from.

Example (Empty Form)

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_box('title') ?>
	</div>
</form>

Example (Auto Filled)

<?php $form = $simpleAdmin->form->form_for('products', 3); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_box('title') ?>
	</div>
</form>

Example (Default Value)

<?php $form = $simpleAdmin->form->form_for('products', array(
	'title' => 'Filled with simpleAdminPlus'
)); ?>
<form method="post">
<div class="input_field">
	<?= $form->label('title') ?>
	<?= $form->input_box('title') ?>
</div>
</form>
multi_part() $simpleAdmin->form->multi_part()
mulit_part() – Echos enctype="multipart/form-data" so you don't have to remember it.

Usage

$simpleAdmin->form->multi_part()

Example

<?php $form = $simpleAdmin->form->form_for('products') ?>
<form <?= $form->multi_part() ?> method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_field('title') ?>
	</div>
</form>
label() $simpleAdmin->form->label()
label() – Creates a label for an input_box, textarea, or select box.

Usage

$simpleAdmin->form->label( [column_name], [text] )
column_name string (required)
The name of the column from the table.
text string (default=null)
This is the text visible from the label. If left blank it will be the value of the column name with a capital letter.

Example

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_box('title') ?>
	</div>
</form>

Example (Custom Text)

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title', 'Product Title') ?>
		<?= $form->input_box('title') ?>
	</div>
</form>
input_box() $simpleAdmin->form->input_box()
input_box() – Creates an input box.

Usage

$simpleAdmin->form->input_box( [column_name], [attributes] )
column_name string (required)
The name of the column from the table. (Used to auto fill)
attributes array (default=null)
This is used to create attributes for the input box. (e.g size="50")

Example

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_box('title') ?>
	</div>
</form>

Example (Custom Attributes)

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('title') ?>
		<?= $form->input_box('title', array(
				'class' => 'input title',
				'size' => '50',
			)) ?>
	</div>
</form>
text_box() $simpleAdmin->form->text_box()
text_box() – Creates a textarea.

Usage

$simpleAdmin->form->text_box( [column_name], [attributes] )
column_name string (required)
The name of the column from the table. (Used to auto fill)
attributes array (default=null)
This is used to create attributes for the textarea. (e.g rows="6")

Example

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('description') ?>
		<?= $form->text_box('description') ?>
	</div>
</form>

Example (Custom Attributes)

<?php $form = $simpleAdmin->form->form_for('products'); ?>
<form method="post">
	<div class="input_field">
		<?= $form->label('description') ?>
		<?= $form->text_box('description', array(
				'class' => 'text description',
				'rows' => '6',
			)) ?>
	</div>
</form>
select_box() $simpleAdmin->form->select_box()
select_box() – Creates a select box.

Usage

$simpleAdmin->form->select_box( [column_name], [data], [value], [text], [attributes] )
column_name string (required)
The name of the column from the table. (Used to auto fill)
data string or array (required)
If you want to get rows from a table then use a string for the table name, but if you want to create a rows manually then supply an array.
value string (required if your using a table)
This is the text of the attribute for the option.
text string (required if your using a table)
This is the text that goes inside of the option tags.
attributes array (default=null)
This is used to create attributes for the select box. (e.g class="category_id")

Example (Simple)

<?php $form = $simpleAdmin->form->form_for('products') ?>
<form method="post">
<div class="input_field">
	<?= $form->label('category_id', 'Category') ?>
	<?= $form->select_box('category_id', 'categories', 'id', 'name') ?>
</div>
</form>

Example (Custom Input)

<?php $form = $simpleAdmin->form->form_for('products') ?>
<form method="post">
<div class="input_field">
	<?= $form->label('category_id', 'Category') ?>
	<?= $form->select_box('category_id', array(
			'1' => 'Web Design',
			'2' => 'Photoshop',
			'3' => 'PHP & jQuery'
		)) ?>
</div>
</form>
submit() $simpleAdmin->form->submit()
submit() – Creates a submit button.

Usage

$simpleAdmin->form->submit( [text], [attributes] )
text string (default=Save Changes)
The name of the column from the table. (Used to auto fill)
attributes array (default=null)
This is used to create attributes for the submit button. (e.g class="submit")

Example

<?php $form = $simpleAdmin->form->form_for('products') ?>
<form method="post">
	<div class="submit_field">
		<?= $form->submit() ?>
	</div>
</form>

Validating functions

These functions are also located in $simpleAdmin->form

validate() $simpleAdmin->form->validate()
validate() – Initializes the validate functions.

Usage

$simpleAdmin->form->validate( [table_name] )
table_name string (required)
This is the table name that you used to create the form.

Example

<?php
$validate = $simpleAdmin->form->validate('products');

$validate->presence_of('title');

if( $validate->has_errors() ) {
	$validate->get_errors();
}
?>
presence_of() $simpleAdmin->form->presence_of()
presence_of() – Initializes the validate functions.

Usage

$simpleAdmin->form->presence_of( [column_name], [options] )
column_name string (required)
This is the column name from the table.
options array (default=null)
This is used to check for a minimum and or maximum length and whether or not to run mysql_real_escape_string

Example (With All Options)

<?php
$validate = $simpleAdmin->form->validate('products');

$validate->presence_of('title', array(
	'min_length' => 25, // Min length of 25 characters
	'max_length' => 150, // Max length of 150 characters
	'escape' => true // runs mysql_real_escape_string (default=true)
));

if( $validate->has_errors() ) {
	$validate->get_errors();
}
?>
has_errors() $simpleAdmin->form->has_errors()
has_errors() – Returns true if there are any errors in the validation

Usage

$simpleAdmin->form->has_errors()

Example

<?php
$validate = $simpleAdmin->form->validate('products');

$validate->presence_of('title');

if( $validate->has_errors() ) {
	$validate->get_errors();
}
?>
get_errors() $simpleAdmin->form->get_errors()

get_errors() – Echos out the error messages in a paragraph tag with a class of form_error and wraps the field name in a span with the class of field_name.


Usage

$simpleAdmin->form->get_errors()

Example

<?php
$validate = $simpleAdmin->form->validate('products');

$validate->presence_of('title');

if( $validate->has_errors() ) {
	$validate->get_errors();
}
?>