Source for file ScForms.php
Documentation is available at ScForms.php
* An open source SmartClient View Helper for Zend Framework
* @author Fernando Marcelo Morgenstern <fernando@consultorpc.com>
* @copyright Copyright (c) 2009, ConsultorPC
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html
* @link http://smartclientphp.com/
* Smart Client Forms Helper
* @uses viewHelper SmartClient
* @var Zend_View_Interface
* @var string Default title orientation for the form fields
* @param $view Zend_View_Interface
public function setView( Zend_View_Interface $view )
* @param mixed $data If string, it must be the title of the field. If array, them we will loop on it
* @param array $options Additional options
public function addButton( $data , $click = '' , $options = '' )
// Check if it is an array
$newField['title'] = $data;
$newField['click'] = $click;
$newField['type'] = 'button';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param boolean $checked Default value
* @param array $options Additional options
public function addCheckboxField( $data , $title = '' , $checked = false , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $checked;
$newField['type'] = 'checkbox';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param string $defaultValue Default value
* @param boolean $useTextField Use a text field
* @param string $dateDisplayFormat Display format
* @param string $startDate Start date
* @param string $endDate End date
* @param array $options Additional options
public function addDateField( $data , $title = '' , $defaultValue = '' , $useTextField = false , $dateDisplayFormat = '' , $startDate = '' , $endDate = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $defaultValue;
$newField['useTextField'] = $useTextField;
$newField['dateDisplayFormat'] = $dateDisplayFormat;
$newField['startDate'] = $startDate;
$newField['endDate'] = $endDate;
$newField['type'] = 'date';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the value of the field. If array, them we will loop on it
* @param array $options Additional options
public function addHeader( $data , $options = '' )
// Check if it is an array
$newField['defaultValue'] = $data;
$newField['type'] = 'header';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $defaultValue Default value for the hidden field
* @param array $options Additional options
public function addHiddenField( $data , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'hidden';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param float $min Min value
* @param float $max Max value
* @param float $step Step value
* @param float $defaultValue Default value
* @param array $options Additional options
public function addSpinnerField( $data , $title = '' , $min = '' , $max = '' , $step = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['step'] = $step;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'spinner';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param string $defaultValue Default value for the text area
* @param array $options Additional options
public function addPasswordField( $data , $title = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'password';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param float $min Min value
* @param float $max Max value
* @param float $step Step value
* @param float $defaultValue Default value
* @param array $options Additional options
public function addSliderField( $data , $title = '' , $minValue = '' , $maxValue = '' , $numValues = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['minValue'] = $minValue;
$newField['maxValue'] = $maxValue;
$newField['numValues'] = $numValues;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'slider';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be a unique value for this section. If array, them we will loop on it
* @param string $defaultValue Title of the section
* @param array $itemIds Fields on this section
* @param boolean $sectionExpanded True if section is expanded
* @param array $options Additional options
public function addSection( $data , $defaultValue = '' , $itemIds = '' , $sectionExpanded = true , $options = '' )
// Check if it is an array
$newField['defaultValue'] = $defaultValue;
$newField['itemIds'] = $itemIds;
$newField['sectionExpanded'] = $sectionExpanded;
$newField['type'] = 'section';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
$this->_currentSection = $newField['ID'];
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param array $valueMap Array containing the values for this select field
* @param mixed $defaultValue Default value
* @param array $options Additional options
public function addSelectField( $data , $title = '' , $valueMap = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['valueMap'] = $valueMap;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'select';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the value of the field. If array, them we will loop on it
* @param array $options Additional options
// Check if it is an array
$newField['title'] = $data;
$newField['type'] = 'submit';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param string $defaultValue Default value for the text area
* @param array $options Additional options
public function addTextArea( $data , $title = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'textArea';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param string $defaultValue Default value for the text area
* @param array $options Additional options
public function addTextField( $data , $title = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'text';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* @param mixed $data If string, it must be the name of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param string $defaultValue Default value
* @param array $options Additional options
public function addTimeField( $data , $title = '' , $defaultValue = '' , $options = '' )
// Check if it is an array
$newField['name'] = $data;
$newField['title'] = $title;
$newField['defaultValue'] = $defaultValue;
$newField['type'] = 'time';
// Set default value for titleOrientation if it is not set
if ( empty( $options['titleOrientation'] ) )
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newField[$name] = $value;
// Add field to the array
* Return the current fields array
* Create the dynamic form
* @param mixed $data If string, it must be the id of the form. If array, them we will loop through it
* @param string $action Action of the form
* @param array $options Additional options
public function create( $data , $action = '' , $options = '' )
// Check if it is an array
// Add vars to the new form
$newForm['action'] = $action;
$newForm['fields'] = $this->_fields;
// Set the default value for canSubmit
if ( !isset ( $options['canSubmit'] ) )
$options['canSubmit'] = true;
// Set the default value for position
if ( !isset ( $options['position'] ) )
$options['position'] = 'relative';
// Set the default value for saveOnEnter
if ( !isset ( $options['saveOnEnter'] ) )
$options['saveOnEnter'] = true;
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newForm[$name] = $value;
$dataEncoded = Zend_Json::encode( $newForm );
// Remove vars that shouldn't be quoted
<script type="text/javascript">
|