2005-07-21 04:02:32 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2005-09-07 01:52:45 +00:00
|
|
|
* Automatic generation of HTML FORMs from given data.
|
2005-12-23 21:57:26 +00:00
|
|
|
*
|
2005-09-07 01:52:45 +00:00
|
|
|
* Used for scaffolding.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2006-05-26 05:29:17 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* @filesource
|
2006-05-26 05:29:17 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
* @since CakePHP v 0.10.0.1076
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-07-22 14:13:07 +00:00
|
|
|
|
|
|
|
/* Deprecated */
|
|
|
|
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Tag template for a div with a class attribute.
|
2006-11-30 18:07:08 +00:00
|
|
|
* @deprecated
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
define('TAG_DIV', '<div class="%s">%s</div>');
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Tag template for a paragraph with a class attribute.
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
define('TAG_P_CLASS', '<p class="%s">%s</p>');
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Tag template for a label with a for attribute.
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
define('TAG_LABEL', '<label for="%s">%s</label>');
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Tag template for a fieldset with a legend tag inside.
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
|
|
|
* Form helper library.
|
2005-12-23 21:57:26 +00:00
|
|
|
*
|
2005-09-07 01:52:45 +00:00
|
|
|
* Automatic generation of HTML FORMs from given data.
|
2005-07-21 04:02:32 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2006-10-27 21:40:34 +00:00
|
|
|
class FormHelper extends AppHelper {
|
2006-07-22 14:13:07 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
var $helpers = array('Html');
|
2006-08-04 08:03:39 +00:00
|
|
|
|
2006-11-26 20:43:54 +00:00
|
|
|
var $Html = null;
|
|
|
|
|
2006-12-22 05:23:07 +00:00
|
|
|
var $__options = array(
|
|
|
|
'day' => array(), 'minute' => array(), 'hour' => array(),
|
|
|
|
'month' => array(), 'year' => array(), 'meridian' => array()
|
|
|
|
);
|
|
|
|
|
2006-08-04 08:03:39 +00:00
|
|
|
/**
|
|
|
|
* Returns an HTML FORM element.
|
|
|
|
*
|
2006-11-29 07:58:35 +00:00
|
|
|
* @access public
|
2006-11-26 20:43:54 +00:00
|
|
|
* @param string $model The model object which the form is being defined for
|
|
|
|
* @param array $options
|
2006-08-04 08:03:39 +00:00
|
|
|
* @return string An formatted opening FORM tag.
|
|
|
|
*/
|
2006-11-26 20:43:54 +00:00
|
|
|
function create($model = null, $options = array()) {
|
2006-12-22 05:23:07 +00:00
|
|
|
if (is_array($model) && empty($options)) {
|
|
|
|
$options = $model;
|
|
|
|
}
|
2007-01-16 07:07:49 +00:00
|
|
|
|
|
|
|
if ($model !== false) {
|
2006-12-22 05:23:07 +00:00
|
|
|
$model = $this->params['models'][0];
|
2006-11-26 20:43:54 +00:00
|
|
|
}
|
2007-01-16 07:07:49 +00:00
|
|
|
|
2006-11-26 20:43:54 +00:00
|
|
|
if (ClassRegistry::isKeySet($model)) {
|
|
|
|
$object =& ClassRegistry::getObject($model);
|
|
|
|
}
|
|
|
|
|
2007-01-03 17:36:14 +00:00
|
|
|
$this->setFormTag($model . '/');
|
2006-11-26 20:43:54 +00:00
|
|
|
$append = '';
|
|
|
|
$created = false;
|
2007-01-03 17:36:14 +00:00
|
|
|
|
|
|
|
if(isset($object)) {
|
2007-01-01 19:39:07 +00:00
|
|
|
$fields = $object->loadInfo();
|
|
|
|
$data = array(
|
|
|
|
'fields' => array_combine($fields->extract('{n}.name'), $fields->extract('{n}.type')),
|
|
|
|
'key' => $object->primaryKey,
|
2007-01-06 00:47:54 +00:00
|
|
|
'validates' => (empty($object->validate) ? array() : array_keys($object->validate))
|
2007-01-01 19:39:07 +00:00
|
|
|
);
|
|
|
|
}
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-11-27 19:56:06 +00:00
|
|
|
if (isset($this->data[$model]) && isset($this->data[$model][$data['key']]) && !empty($this->data[$model][$data['key']])) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$created = true;
|
|
|
|
}
|
2006-12-21 06:10:35 +00:00
|
|
|
$options = am(array(
|
|
|
|
'type' => ($created && empty($options['action'])) ? 'put' : 'post',
|
|
|
|
'id' => $model . ($created ? 'Edit' : 'Add') . 'Form',
|
|
|
|
'action' => array(),
|
|
|
|
'default' => true),
|
|
|
|
$options);
|
2006-11-26 20:43:54 +00:00
|
|
|
|
|
|
|
if (empty($options['action']) || is_array($options['action'])) {
|
2006-12-01 19:04:16 +00:00
|
|
|
$options = (array)$options;
|
2006-11-26 20:43:54 +00:00
|
|
|
$actionDefaults = array(
|
2006-12-19 19:31:14 +00:00
|
|
|
'controller' => Inflector::underscore($this->params['controller']),
|
2006-12-08 08:45:35 +00:00
|
|
|
'action' => $created ? 'edit' : 'add',
|
2006-12-01 19:04:16 +00:00
|
|
|
'id' => $created ? $this->data[$model][$data['key']] : null
|
2006-11-26 20:43:54 +00:00
|
|
|
);
|
|
|
|
$options['action'] = am($actionDefaults, $options['action']);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (low($options['type'])) {
|
|
|
|
case 'get':
|
2006-12-01 19:04:16 +00:00
|
|
|
$htmlAttributes['method'] = 'get';
|
2006-11-26 20:43:54 +00:00
|
|
|
break;
|
2006-12-01 19:04:16 +00:00
|
|
|
case 'file':
|
|
|
|
$htmlAttributes['enctype'] = 'multipart/form-data';
|
|
|
|
$options['type'] = $created ? 'put' : 'post';
|
|
|
|
case 'post':
|
2006-11-26 20:43:54 +00:00
|
|
|
case 'put':
|
|
|
|
case 'delete':
|
|
|
|
$append .= $this->hidden('method/method', array('value' => up($options['type'])));
|
|
|
|
default:
|
2006-12-01 19:04:16 +00:00
|
|
|
$htmlAttributes['method'] = 'post';
|
2006-11-26 20:43:54 +00:00
|
|
|
break;
|
2006-08-04 08:03:39 +00:00
|
|
|
}
|
2006-12-21 04:46:52 +00:00
|
|
|
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes['action'] = $this->url($options['action']);
|
|
|
|
unset($options['type'], $options['action']);
|
2006-12-21 06:10:35 +00:00
|
|
|
|
|
|
|
if ($options['default'] == false) {
|
|
|
|
if (isset($htmlAttributes['onSubmit'])) {
|
|
|
|
$htmlAttributes['onSubmit'] .= ' return false;';
|
|
|
|
} else {
|
|
|
|
$htmlAttributes['onSubmit'] = 'return false;';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($options['default']);
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes = am($options, $htmlAttributes);
|
2006-08-04 08:03:39 +00:00
|
|
|
|
2006-11-26 20:43:54 +00:00
|
|
|
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
|
|
|
|
$append .= $this->hidden('_Token/key', array('value' => $this->params['_Token']['key']));
|
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
|
|
|
|
$this->setFormTag($model . '/');
|
2006-11-26 20:43:54 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['form'], $this->Html->parseHtmlOptions($htmlAttributes, null, ''))) . $append;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Closes an HTML form.
|
|
|
|
*
|
2006-11-29 07:58:35 +00:00
|
|
|
* @access public
|
2006-11-26 20:43:54 +00:00
|
|
|
* @return string A closing FORM tag.
|
|
|
|
*/
|
|
|
|
function end($model = null) {
|
2006-11-27 04:46:25 +00:00
|
|
|
if (empty($model) && !empty($this->params['models'])) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$models = $this->params['models'][0];
|
|
|
|
}
|
|
|
|
return $this->output($this->Html->tags['formend']);
|
2006-08-04 08:03:39 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-12-31 08:28:55 +00:00
|
|
|
* Returns true if there is an error for the given field, otherwise false
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2006-11-29 07:58:35 +00:00
|
|
|
* @access public
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $field This should be "Modelname/fieldname"
|
|
|
|
* @return bool If there are errors this method returns true, else false.
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function isFieldError($field) {
|
2006-12-31 08:28:55 +00:00
|
|
|
$this->setFormTag($field);
|
|
|
|
return (bool)$this->tagIsInvalid();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns a formatted error message for given FORM field, NULL if no errors.
|
|
|
|
*
|
|
|
|
* @param string $field A field name, like "Modelname/fieldname"
|
|
|
|
* @param string $text Error message
|
|
|
|
* @param array $options Rendering options for <div /> wrapper tag
|
|
|
|
* @return string If there are errors this method returns an error message, otherwise null.
|
|
|
|
*/
|
|
|
|
function error($field, $text = null, $options = array()) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$this->setFormTag($field);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-11-26 20:43:54 +00:00
|
|
|
if ($error == $this->tagIsInvalid()) {
|
2006-12-31 08:28:55 +00:00
|
|
|
if ($text != null) {
|
|
|
|
$error = $text;
|
|
|
|
} elseif (is_numeric($error)) {
|
|
|
|
$error = 'Error in field ' . Inflector::humanize($this->field());
|
|
|
|
}
|
|
|
|
return $this->Html->div('error-message', $error);
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2006-12-31 08:28:55 +00:00
|
|
|
return null;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Returns a formatted LABEL element for HTML FORMs.
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $tagName This should be "Modelname/fieldname"
|
|
|
|
* @param string $text Text that will appear in the label field.
|
|
|
|
* @return string The formatted LABEL element
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-12-08 08:45:35 +00:00
|
|
|
function label($tagName = null, $text = null, $attributes = array()) {
|
|
|
|
if (empty($tagName)) {
|
|
|
|
$tagName = implode('/', array_filter(array($this->model(), $this->field())));
|
|
|
|
}
|
|
|
|
|
2006-08-30 16:23:24 +00:00
|
|
|
if ($text == null) {
|
|
|
|
if (strpos($tagName, '/') !== false) {
|
|
|
|
list( , $text) = explode('/', $tagName);
|
|
|
|
} else {
|
|
|
|
$text = $tagName;
|
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
if (substr($text, -3) == '_id') {
|
|
|
|
$text = substr($text, 0, strlen($text) - 3);
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
$text = Inflector::humanize($text);
|
|
|
|
}
|
2006-07-25 02:18:37 +00:00
|
|
|
if (strpos($tagName, '/') !== false) {
|
|
|
|
$tagName = Inflector::camelize(r('/', '_', $tagName));
|
|
|
|
}
|
2006-11-22 03:51:21 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['label'], $tagName, $this->_parseAttributes($attributes), $text));
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
/**
|
|
|
|
* Will display all the fields passed in an array expects tagName as an array key
|
2006-11-27 01:04:19 +00:00
|
|
|
* replaces generateFields
|
|
|
|
*
|
2006-11-29 07:58:35 +00:00
|
|
|
* @access public
|
2006-11-27 01:04:19 +00:00
|
|
|
* @param array $fields works well with Controller::generateFieldNames();
|
2006-11-30 18:07:08 +00:00
|
|
|
* @return output
|
|
|
|
*/
|
2006-12-08 08:45:35 +00:00
|
|
|
function inputs($fields) {
|
2006-11-27 01:04:19 +00:00
|
|
|
$out = null;
|
|
|
|
foreach($fields as $name => $options) {
|
2006-12-08 08:45:35 +00:00
|
|
|
if (is_numeric($name) && !is_array($options)) {
|
|
|
|
$name = $options;
|
|
|
|
$options = array();
|
|
|
|
}
|
|
|
|
if(is_array($options) && isset($options['tagName'])) {
|
|
|
|
$name = $options['tagName'];
|
2006-11-27 01:04:19 +00:00
|
|
|
unset($options['tagName']);
|
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
$out .= $this->input($name, $options);
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
return $out;
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
/**
|
|
|
|
* Generates a form input element complete with label and wrapper div
|
|
|
|
*
|
|
|
|
* @param string $tagName This should be "Modelname/fieldname"
|
|
|
|
* @param array $options
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function input($tagName, $options = array()) {
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-09-29 01:32:09 +00:00
|
|
|
$this->setFormTag($tagName);
|
|
|
|
|
2007-01-14 05:46:03 +00:00
|
|
|
if ((!isset($options['type']) || $options['type'] == 'select') && !isset($options['options'])) {
|
2006-12-21 04:46:52 +00:00
|
|
|
if (ClassRegistry::isKeySet($this->model())) {
|
|
|
|
|
|
|
|
$model =& ClassRegistry::getObject($this->model());
|
|
|
|
if ($model->isForeignKey($this->field())) {
|
|
|
|
|
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
$varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $this->field())));
|
|
|
|
$varOptions = $view->getVar($varName);
|
|
|
|
|
|
|
|
if (is_array($options)) {
|
|
|
|
$options['type'] = 'select';
|
|
|
|
$options['options'] = $varOptions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 16:23:24 +00:00
|
|
|
if (!isset($options['type'])) {
|
2006-12-08 08:45:35 +00:00
|
|
|
$options['type'] = 'text';
|
|
|
|
|
2006-08-30 16:23:24 +00:00
|
|
|
if (isset($options['options'])) {
|
|
|
|
$options['type'] = 'select';
|
2006-12-08 08:45:35 +00:00
|
|
|
} elseif (in_array($this->field(), array('passwd', 'password'))) {
|
2006-09-29 01:32:09 +00:00
|
|
|
$options['type'] = 'password';
|
2006-12-08 08:45:35 +00:00
|
|
|
} elseif (ClassRegistry::isKeySet($this->model())) {
|
|
|
|
$model =& ClassRegistry::getObject($this->model());
|
|
|
|
$type = $model->getColumnType($this->field());
|
|
|
|
$map = array(
|
2006-12-12 22:43:01 +00:00
|
|
|
'string' => 'text', 'datetime' => 'datetime',
|
2006-12-08 08:45:35 +00:00
|
|
|
'boolean' => 'checkbox', 'timestamp' => 'datetime',
|
|
|
|
'text' => 'textarea', 'time' => 'time',
|
|
|
|
'date' => 'date'
|
|
|
|
);
|
|
|
|
if (isset($map[$type])) {
|
|
|
|
$options['type'] = $map[$type];
|
|
|
|
}
|
2006-12-12 22:43:01 +00:00
|
|
|
if($this->field() == $model->primaryKey) {
|
|
|
|
$options['type'] = 'hidden';
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-22 16:26:54 +00:00
|
|
|
$out = '';
|
2006-12-08 08:45:35 +00:00
|
|
|
$div = true;
|
|
|
|
if (isset($options['div'])) {
|
|
|
|
$div = $options['div'];
|
|
|
|
unset($options['div']);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$divOptions = array();
|
2006-12-08 08:45:35 +00:00
|
|
|
if ($div === true) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$divOptions['class'] = 'input';
|
2006-12-08 08:45:35 +00:00
|
|
|
} elseif ($div === false) {
|
|
|
|
unset($divOptions);
|
|
|
|
} elseif (is_string($div)) {
|
|
|
|
$divOptions['class'] = $div;
|
|
|
|
} elseif (is_array($div)) {
|
|
|
|
$divOptions = am(array('class' => 'input'), $div);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$label = null;
|
|
|
|
if (isset($options['label'])) {
|
|
|
|
$label = $options['label'];
|
|
|
|
unset($options['label']);
|
|
|
|
}
|
2006-12-22 05:23:07 +00:00
|
|
|
if (is_array($label)) {
|
|
|
|
$labelText = null;
|
|
|
|
if (isset($label['text'])) {
|
|
|
|
$labelText = $label['text'];
|
|
|
|
unset($label['text']);
|
|
|
|
}
|
|
|
|
$out = $this->label(null, $labelText, $label);
|
|
|
|
$label = $labelText;
|
2006-12-22 16:26:54 +00:00
|
|
|
} elseif ($label !== false) {
|
2006-12-22 05:23:07 +00:00
|
|
|
$out = $this->label(null, $label);
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
|
|
|
|
$error = null;
|
|
|
|
if (isset($options['error'])) {
|
|
|
|
$error = $options['error'];
|
|
|
|
unset($options['error']);
|
2006-11-27 19:56:06 +00:00
|
|
|
} else {
|
|
|
|
$error = $label . ' is required';
|
|
|
|
}
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-11-27 01:04:19 +00:00
|
|
|
$selected = null;
|
2006-11-29 10:21:22 +00:00
|
|
|
if (array_key_exists('selected', $options)) {
|
2006-11-27 01:04:19 +00:00
|
|
|
$selected = $options['selected'];
|
|
|
|
unset($options['selected']);
|
2006-11-30 18:07:08 +00:00
|
|
|
}
|
2007-01-01 19:39:07 +00:00
|
|
|
if(isset($options['rows']) || isset($options['cols'])) {
|
|
|
|
$options['type'] = 'textarea';
|
|
|
|
}
|
2007-01-14 05:46:03 +00:00
|
|
|
|
2007-01-11 00:11:55 +00:00
|
|
|
$empty = false;
|
|
|
|
if(isset($options['empty'])) {
|
|
|
|
$empty = $options['empty'];
|
|
|
|
unset($options['empty']);
|
|
|
|
}
|
2006-12-24 19:25:04 +00:00
|
|
|
|
2006-12-31 08:28:55 +00:00
|
|
|
$type = $options['type'];
|
|
|
|
unset($options['type']);
|
|
|
|
|
|
|
|
switch ($type) {
|
2006-11-27 01:04:19 +00:00
|
|
|
case 'hidden':
|
2006-12-31 08:28:55 +00:00
|
|
|
$out = $this->hidden($tagName, $options);
|
2006-12-08 08:45:35 +00:00
|
|
|
unset($divOptions);
|
2006-11-27 01:04:19 +00:00
|
|
|
break;
|
|
|
|
case 'checkbox':
|
2006-12-31 08:28:55 +00:00
|
|
|
$out = $this->Html->checkbox($tagName, null, $options) . $out;
|
2006-11-27 01:04:19 +00:00
|
|
|
break;
|
2006-08-30 16:23:24 +00:00
|
|
|
case 'text':
|
2006-11-27 01:04:19 +00:00
|
|
|
$out .= $this->text($tagName, $options);
|
2006-08-30 16:23:24 +00:00
|
|
|
break;
|
2006-09-29 01:32:09 +00:00
|
|
|
case 'password':
|
2006-11-27 01:04:19 +00:00
|
|
|
$out .= $this->password($tagName, $options);
|
2006-09-29 01:32:09 +00:00
|
|
|
break;
|
2006-08-30 16:23:24 +00:00
|
|
|
case 'file':
|
|
|
|
$out .= $this->Html->file($tagName);
|
|
|
|
break;
|
|
|
|
case 'select':
|
2007-01-11 00:11:55 +00:00
|
|
|
$list = array();
|
|
|
|
if(isset($options['options'])) {
|
|
|
|
$list = $options['options'];
|
|
|
|
unset($options['options']);
|
|
|
|
}
|
2006-11-29 10:21:22 +00:00
|
|
|
$out .= $this->select($tagName, $list, $selected, $options, $empty);
|
2006-08-30 16:23:24 +00:00
|
|
|
break;
|
2006-11-27 01:04:19 +00:00
|
|
|
case 'time':
|
2007-01-11 00:11:55 +00:00
|
|
|
$out .= $this->Html->dateTimeOptionTag($tagName, null, '12', $selected, $options, null, $empty);
|
2006-11-27 01:04:19 +00:00
|
|
|
break;
|
|
|
|
case 'date':
|
2007-01-11 00:11:55 +00:00
|
|
|
$out .= $this->Html->dateTimeOptionTag($tagName, 'MDY', null, $selected, $options, null, $empty);
|
2006-11-27 01:04:19 +00:00
|
|
|
break;
|
|
|
|
case 'datetime':
|
2007-01-11 00:11:55 +00:00
|
|
|
$out .= $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $options, null, $empty);
|
2006-11-27 01:04:19 +00:00
|
|
|
break;
|
2006-09-29 01:32:09 +00:00
|
|
|
case 'textarea':
|
|
|
|
default:
|
2006-12-08 08:45:35 +00:00
|
|
|
$out .= $this->textarea($tagName, am(array('cols' => '30', 'rows' => '10'), $options));
|
2006-09-29 01:32:09 +00:00
|
|
|
break;
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($error != null) {
|
|
|
|
$out .= $this->Html->tagErrorMsg($tagName, $error);
|
|
|
|
}
|
|
|
|
|
2006-12-08 08:45:35 +00:00
|
|
|
if (isset($divOptions)) {
|
|
|
|
$out = $this->Html->div($divOptions['class'], $out, $divOptions);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
return $out;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-07-22 14:13:07 +00:00
|
|
|
/**
|
|
|
|
* Creates a text input widget.
|
|
|
|
*
|
|
|
|
* @param string $fieldNamem Name of a field, like this "Modelname/fieldname"
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string An HTML text input element
|
|
|
|
*/
|
|
|
|
function text($fieldName, $htmlAttributes = null) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$htmlAttributes = $this->__value($htmlAttributes, $fieldName);
|
|
|
|
$htmlAttributes = $this->domId($htmlAttributes);
|
2006-07-22 14:13:07 +00:00
|
|
|
|
|
|
|
if (!isset($htmlAttributes['type'])) {
|
|
|
|
$htmlAttributes['type'] = 'text';
|
|
|
|
}
|
|
|
|
|
2006-08-30 16:23:24 +00:00
|
|
|
if ($this->tagIsInvalid()) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes = $this->addClass($htmlAttributes, 'form-error');
|
2006-07-22 14:13:07 +00:00
|
|
|
}
|
2006-11-22 03:51:21 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['input'], $this->model(), $this->field(), $this->_parseAttributes($htmlAttributes, null, ' ', ' ')));
|
2006-07-22 14:13:07 +00:00
|
|
|
}
|
2006-09-29 01:32:09 +00:00
|
|
|
/**
|
|
|
|
* Creates a password input widget.
|
|
|
|
*
|
|
|
|
* @param string $fieldName Name of a field, like this "Modelname/fieldname"
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string
|
|
|
|
*/
|
2006-12-31 08:28:55 +00:00
|
|
|
function password($fieldName, $htmlAttributes = array()) {
|
2006-09-29 01:32:09 +00:00
|
|
|
$htmlAttributes = $this->__value($htmlAttributes, $fieldName);
|
|
|
|
$htmlAttributes = $this->domId($htmlAttributes);
|
|
|
|
if ($this->tagIsInvalid()) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes = $this->addClass($htmlAttributes, 'form-error');
|
2006-09-29 01:32:09 +00:00
|
|
|
}
|
2006-11-22 03:51:21 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['password'], $this->model(), $this->field(), $this->_parseAttributes($htmlAttributes, null, ' ', ' ')));
|
2006-09-29 01:32:09 +00:00
|
|
|
}
|
2006-08-22 19:35:08 +00:00
|
|
|
/**
|
|
|
|
* Creates a textarea widget.
|
|
|
|
*
|
|
|
|
* @param string $fieldNamem Name of a field, like this "Modelname/fieldname"
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string An HTML text input element
|
|
|
|
*/
|
2006-12-31 08:28:55 +00:00
|
|
|
function textarea($fieldName, $htmlAttributes = array()) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes = $this->__value($htmlAttributes, $fieldName);
|
|
|
|
$htmlAttributes = $this->domId($htmlAttributes);
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-11-29 10:21:22 +00:00
|
|
|
if (isset($htmlAttributes['type'])) {
|
|
|
|
unset($htmlAttributes['type']);
|
|
|
|
}
|
2006-11-27 01:04:19 +00:00
|
|
|
$value = null;
|
2006-11-29 10:21:22 +00:00
|
|
|
if (array_key_exists('value', $htmlAttributes)) {
|
2006-08-22 19:35:08 +00:00
|
|
|
$value = $htmlAttributes['value'];
|
|
|
|
unset($htmlAttributes['value']);
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
if ($this->tagIsInvalid()) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$htmlAttributes = $this->addClass($htmlAttributes, 'form-error');
|
2006-08-22 19:35:08 +00:00
|
|
|
}
|
2006-11-22 03:51:21 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['textarea'], $this->model(), $this->field(), $this->Html->_parseAttributes($htmlAttributes, null, ' '), $value));
|
2006-08-22 19:35:08 +00:00
|
|
|
}
|
2006-11-26 20:43:54 +00:00
|
|
|
/**
|
|
|
|
* Creates a hidden input field.
|
|
|
|
*
|
|
|
|
* @param string $fieldName Name of a field, like this "Modelname/fieldname"
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string
|
2006-12-24 19:25:04 +00:00
|
|
|
* @access public
|
2006-11-26 20:43:54 +00:00
|
|
|
*/
|
|
|
|
function hidden($fieldName, $htmlAttributes = array()) {
|
2006-12-24 19:25:04 +00:00
|
|
|
$htmlAttributes = $this->domId($this->__value($htmlAttributes, $fieldName));
|
2006-11-26 20:43:54 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['hidden'], $this->model(), $this->field(), $this->_parseAttributes($htmlAttributes, null, ' ', ' ')));
|
|
|
|
}
|
2006-12-24 19:25:04 +00:00
|
|
|
/**
|
|
|
|
* Creates file input widget.
|
|
|
|
*
|
|
|
|
* @param string $fieldName Name of a field, like this "Modelname/fieldname"
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function file($fieldName, $htmlAttributes = array()) {
|
|
|
|
$htmlAttributes = $this->domId($this->__value($htmlAttributes, $fieldName));
|
|
|
|
return $this->output(sprintf($this->Html->tags['file'], $this->model(), $this->field(), $this->_parseAttributes($htmlAttributes, null, '', ' ')));
|
|
|
|
}
|
2006-07-22 14:13:07 +00:00
|
|
|
/**
|
|
|
|
* Creates a button tag.
|
|
|
|
*
|
|
|
|
* @param mixed $params Array of params [content, type, options] or the
|
|
|
|
* content of the button.
|
|
|
|
* @param string $type Type of the button (button, submit or reset).
|
|
|
|
* @param array $options Array of options.
|
|
|
|
* @return string A HTML button tag.
|
2006-12-24 19:25:04 +00:00
|
|
|
* @access public
|
2006-07-22 14:13:07 +00:00
|
|
|
*/
|
|
|
|
function button($params, $type = 'button', $options = array()) {
|
|
|
|
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__("Don't use me yet"), E_USER_ERROR);
|
2006-07-22 14:13:07 +00:00
|
|
|
if (isset($options['name'])) {
|
|
|
|
if (strpos($options['name'], "/") !== false) {
|
|
|
|
if ($this->fieldValue($options['name'])) {
|
|
|
|
$options['checked'] = 'checked';
|
|
|
|
}
|
|
|
|
$this->setFieldName($options['name']);
|
2006-12-08 08:45:35 +00:00
|
|
|
$options['name'] = 'data[' . $this->model() . '][' . $this->field() . ']';
|
2006-07-22 14:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$options['type'] = $type;
|
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'options' => $this->_parseOptions($options),
|
|
|
|
'tagValue' => $content
|
|
|
|
);
|
|
|
|
return $this->_assign('button', $values);
|
|
|
|
}
|
2006-12-08 08:45:35 +00:00
|
|
|
/**
|
|
|
|
* Creates a submit button element.
|
|
|
|
*
|
|
|
|
* @param string $caption The label appearing on the button
|
|
|
|
* @param array $options
|
|
|
|
* @return string A HTML submit button
|
|
|
|
*/
|
|
|
|
function submit($caption = 'Submit', $options = array()) {
|
|
|
|
$options['value'] = $caption;
|
2006-12-24 19:25:04 +00:00
|
|
|
|
|
|
|
$div = true;
|
|
|
|
if (isset($options['div'])) {
|
|
|
|
$div = $options['div'];
|
|
|
|
unset($options['div']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$divOptions = array();
|
|
|
|
if ($div === true) {
|
|
|
|
$divOptions['class'] = 'submit';
|
|
|
|
} elseif ($div === false) {
|
|
|
|
unset($divOptions);
|
|
|
|
} elseif (is_string($div)) {
|
|
|
|
$divOptions['class'] = $div;
|
|
|
|
} elseif (is_array($div)) {
|
|
|
|
$divOptions = am(array('class' => 'submit'), $div);
|
|
|
|
}
|
2007-01-01 19:39:07 +00:00
|
|
|
|
2006-12-24 19:25:04 +00:00
|
|
|
$out = $this->output(sprintf($this->Html->tags['submit'], $this->_parseAttributes($options, null, '', ' ')));
|
|
|
|
if (isset($divOptions)) {
|
|
|
|
$out = $this->Html->div($divOptions['class'], $out, $divOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
2006-12-08 08:45:35 +00:00
|
|
|
}
|
2006-07-22 14:13:07 +00:00
|
|
|
/**
|
|
|
|
* Creates an image input widget.
|
|
|
|
*
|
|
|
|
* @param string $path Path to the image file, relative to the webroot/img/ directory.
|
|
|
|
* @param array $htmlAttributes Array of HTML attributes.
|
|
|
|
* @return string HTML submit image element
|
|
|
|
*/
|
2006-12-31 08:28:55 +00:00
|
|
|
function submitImage($path, $htmlAttributes = array()) {
|
2006-07-22 14:13:07 +00:00
|
|
|
if (strpos($path, '://')) {
|
|
|
|
$url = $path;
|
|
|
|
} else {
|
2006-07-29 05:59:42 +00:00
|
|
|
$url = $this->webroot . $this->themeWeb . IMAGES_URL . $path;
|
2006-07-22 14:13:07 +00:00
|
|
|
}
|
2006-11-22 03:51:21 +00:00
|
|
|
return $this->output(sprintf($this->Html->tags['submitimage'], $url, $this->_parseAttributes($htmlAttributes, null, '', ' ')));
|
2006-07-22 14:13:07 +00:00
|
|
|
}
|
2006-07-30 12:19:48 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted SELECT element.
|
|
|
|
*
|
|
|
|
* @param string $fieldName Name attribute of the SELECT
|
2006-10-05 08:50:04 +00:00
|
|
|
* @param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
|
2006-11-26 20:43:54 +00:00
|
|
|
* @param mixed $selected The option selected by default. If null, the default value
|
|
|
|
* from POST data will be used when available.
|
|
|
|
* @param array $attributes The HTML attributes of the select element. If
|
|
|
|
* 'showParents' is included in the array and set to true,
|
|
|
|
* an additional option element will be added for the parent
|
|
|
|
* of each option group.
|
|
|
|
* @param mixed $showEmpty If true, the empty select option is shown. If a string,
|
|
|
|
* that string is displayed as the empty element.
|
2006-07-30 12:19:48 +00:00
|
|
|
* @return string Formatted SELECT element
|
|
|
|
*/
|
2006-11-26 20:43:54 +00:00
|
|
|
function select($fieldName, $options = array(), $selected = null, $attributes = array(), $showEmpty = '') {
|
|
|
|
$showParents = false;
|
2006-08-30 16:23:24 +00:00
|
|
|
$this->setFormTag($fieldName);
|
|
|
|
$attributes = $this->domId($attributes);
|
2006-07-30 12:19:48 +00:00
|
|
|
|
2006-08-30 16:23:24 +00:00
|
|
|
if ($this->tagIsInvalid()) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$attributes = $this->addClass($attributes, 'form-error');
|
|
|
|
}
|
2006-12-22 05:23:07 +00:00
|
|
|
if (is_string($options) && isset($this->__options[$options])) {
|
|
|
|
$options = $this->__generateOptions($options);
|
|
|
|
} elseif(!is_array($options)) {
|
2006-11-29 07:58:35 +00:00
|
|
|
$options = array();
|
|
|
|
}
|
2006-11-29 10:21:22 +00:00
|
|
|
if (isset($attributes['type'])) {
|
|
|
|
unset($attributes['type']);
|
|
|
|
}
|
2007-01-01 19:39:07 +00:00
|
|
|
if (in_array('showParents', $attributes)) {
|
2006-11-26 20:43:54 +00:00
|
|
|
$showParents = true;
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-07-30 12:19:48 +00:00
|
|
|
if (!isset($selected)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$selected = $this->__value($fieldName);
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
2006-11-30 18:07:08 +00:00
|
|
|
|
2006-07-30 12:19:48 +00:00
|
|
|
if (isset($attributes) && array_key_exists("multiple", $attributes)) {
|
2006-11-22 03:51:21 +00:00
|
|
|
$tag = $this->Html->tags['selectmultiplestart'];
|
2006-07-30 12:19:48 +00:00
|
|
|
} else {
|
2006-11-22 03:51:21 +00:00
|
|
|
$tag = $this->Html->tags['selectstart'];
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
$select[] = sprintf($tag, $this->model(), $this->field(), $this->Html->parseHtmlOptions($attributes));
|
2006-07-30 12:19:48 +00:00
|
|
|
|
|
|
|
if ($showEmpty !== null && $showEmpty !== false) {
|
2006-09-26 19:53:22 +00:00
|
|
|
if($showEmpty === true) {
|
|
|
|
$showEmpty = '';
|
|
|
|
}
|
2006-12-04 18:00:36 +00:00
|
|
|
$options = array_reverse($options, true);
|
|
|
|
$options[''] = $showEmpty;
|
2006-12-22 22:49:47 +00:00
|
|
|
$options = array_reverse($options, true);
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
2006-11-22 03:32:58 +00:00
|
|
|
$select = am($select, $this->__selectOptions(array_reverse($options, true), $selected, array(), $showParents));
|
2006-11-22 03:51:21 +00:00
|
|
|
$select[] = sprintf($this->Html->tags['selectend']);
|
2006-07-30 12:19:48 +00:00
|
|
|
return $this->output(implode("\n", $select));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns an array of formatted OPTION/OPTGROUP elements
|
2006-08-04 08:03:39 +00:00
|
|
|
*
|
2006-07-30 12:19:48 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2006-09-26 19:53:22 +00:00
|
|
|
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null) {
|
2006-07-30 12:19:48 +00:00
|
|
|
$select = array();
|
|
|
|
foreach($elements as $name => $title) {
|
|
|
|
$htmlOptions = array();
|
|
|
|
if (is_array($title) && (!isset($title['name']) || !isset($title['value']))) {
|
2006-08-07 00:48:25 +00:00
|
|
|
if (!empty($name)) {
|
2006-11-22 03:51:21 +00:00
|
|
|
$select[] = $this->Html->tags['optiongroupend'];
|
2006-09-26 19:53:22 +00:00
|
|
|
$parents[] = $name;
|
2006-08-07 00:48:25 +00:00
|
|
|
}
|
2006-09-26 19:53:22 +00:00
|
|
|
$select = am($select, $this->__selectOptions($title, $selected, $parents, $showParents));
|
2006-08-07 00:48:25 +00:00
|
|
|
if (!empty($name)) {
|
2006-11-22 03:51:21 +00:00
|
|
|
$select[] = sprintf($this->Html->tags['optiongroup'], $name, '');
|
2006-08-07 00:48:25 +00:00
|
|
|
}
|
2006-07-30 12:19:48 +00:00
|
|
|
$name = null;
|
|
|
|
} elseif (is_array($title)) {
|
|
|
|
$htmlOptions = $title;
|
|
|
|
$name = $title['value'];
|
|
|
|
$title = $title['name'];
|
|
|
|
unset($htmlOptions['name'], $htmlOptions['value']);
|
|
|
|
}
|
|
|
|
if ($name !== null) {
|
|
|
|
if (($selected !== null) && ($selected == $name)) {
|
|
|
|
$htmlOptions['selected'] = 'selected';
|
|
|
|
} else if(is_array($selected) && in_array($name, $selected)) {
|
|
|
|
$htmlOptions['selected'] = 'selected';
|
|
|
|
}
|
2006-11-22 03:32:58 +00:00
|
|
|
|
2006-09-26 19:53:22 +00:00
|
|
|
if($showParents || (!in_array($title, $parents))) {
|
2006-11-22 03:51:21 +00:00
|
|
|
$select[] = sprintf($this->Html->tags['selectoption'], $name, $this->Html->parseHtmlOptions($htmlOptions), h($title));
|
2006-09-26 19:53:22 +00:00
|
|
|
}
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-22 03:32:58 +00:00
|
|
|
|
2006-09-28 02:57:29 +00:00
|
|
|
return array_reverse($select, true);
|
2006-07-30 12:19:48 +00:00
|
|
|
}
|
2006-12-22 05:23:07 +00:00
|
|
|
/**
|
|
|
|
* Generates option lists for common <select /> menus
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function __generateOptions($name) {
|
|
|
|
if (!empty($this->options[$name])) {
|
|
|
|
return $this->options[$name];
|
|
|
|
}
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
switch ($name) {
|
|
|
|
case 'minute':
|
|
|
|
for($i = 0; $i < 60; $i++) {
|
|
|
|
$data[$i] = sprintf('%02d', $i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'hour':
|
|
|
|
for($i = 0; $i < 31; $i++) {
|
|
|
|
$data[sprintf('%02d', $i)] = $i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'meridian':
|
|
|
|
$data = array('am' => 'am', 'pm' => 'pm');
|
|
|
|
break;
|
|
|
|
case 'day':
|
|
|
|
for($i = 0; $i < 31; $i++) {
|
|
|
|
$data[sprintf('%02d', $i)] = $i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'month':
|
2006-12-22 22:49:47 +00:00
|
|
|
|
2006-12-22 05:23:07 +00:00
|
|
|
break;
|
|
|
|
case 'year':
|
|
|
|
$current = intval(date('Y'));
|
|
|
|
for ($i = ($current - 20); $i < ($current + 20); $i++) {
|
|
|
|
$data[$i] = $i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$this->__options[$name] = $data;
|
|
|
|
return $this->__options[$name];
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateInputDiv($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() or FormHelper::text() instead'), E_USER_WARNING);
|
2006-05-26 05:29:17 +00:00
|
|
|
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
|
|
|
|
$htmlAttributes = $htmlOptions;
|
|
|
|
$htmlAttributes['size'] = $size;
|
|
|
|
$str = $this->Html->input($tagName, $htmlAttributes);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-05-26 05:29:17 +00:00
|
|
|
$divClass = "optional";
|
|
|
|
if ($required) {
|
|
|
|
$divClass = "required";
|
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-05-26 05:29:17 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
|
|
|
}
|
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
|
|
|
return $this->divTag($divClass, $divTagInside);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateCheckboxDiv($tagName, $prompt, $required = false, $errorMsg = null, $htmlOptions = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() or FormHelper::checkbox() instead'), E_USER_WARNING);
|
2006-06-14 18:02:37 +00:00
|
|
|
$htmlOptions['class'] = "inputCheckbox";
|
|
|
|
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
|
|
|
|
$str = $this->Html->checkbox($tagName, null, $htmlOptions);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "optional";
|
|
|
|
if ($required) {
|
|
|
|
$divClass = "required";
|
|
|
|
}
|
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->divTag($divClass, $divTagInside);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateDate($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() instead'), E_USER_WARNING);
|
2006-05-26 05:29:17 +00:00
|
|
|
$htmlOptions['id']=strtolower(str_replace('/', '_', $tagName));
|
2006-06-14 18:02:37 +00:00
|
|
|
$str = $this->Html->dateTimeOptionTag($tagName, 'MDY', 'NONE', $selected, $htmlOptions);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "optional";
|
|
|
|
if ($required) {
|
|
|
|
$divClass = "required";
|
|
|
|
}
|
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
|
|
|
$requiredDiv = $this->divTag($divClass, $divTagInside);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->divTag("date", $requiredDiv);
|
|
|
|
}
|
2006-07-29 18:01:50 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2006-07-29 18:01:50 +00:00
|
|
|
*/
|
|
|
|
function generateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() instead'), E_USER_WARNING);
|
2006-07-29 18:01:50 +00:00
|
|
|
$str = $this->Html->dateTimeOptionTag($tagName, 'NONE', '24', $selected, $htmlOptions);
|
2006-07-29 18:12:45 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-07-29 18:01:50 +00:00
|
|
|
$divClass = "optional";
|
|
|
|
if ($required) {
|
|
|
|
$divClass = "required";
|
|
|
|
}
|
|
|
|
$strError = "";
|
|
|
|
|
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-07-29 18:01:50 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
|
|
|
}
|
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
|
|
|
$requiredDiv = $this->divTag($divClass, $divTagInside);
|
|
|
|
return $this->divTag("time", $requiredDiv);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateDateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() instead'), E_USER_WARNING);
|
2006-05-26 05:29:17 +00:00
|
|
|
$htmlOptions['id']=strtolower(str_replace('/', '_', $tagName));
|
2006-11-27 01:04:19 +00:00
|
|
|
$str = $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $htmlOptions, null, false);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "optional";
|
|
|
|
if ($required) {
|
|
|
|
$divClass = "required";
|
|
|
|
}
|
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
|
|
|
$requiredDiv = $this->divTag($divClass, $divTagInside);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->divTag("date", $requiredDiv);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateAreaDiv($tagName, $prompt, $required = false, $errorMsg = null, $cols = 60, $rows = 10, $htmlOptions = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() instead'), E_USER_WARNING);
|
2006-06-14 18:02:37 +00:00
|
|
|
$htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName));
|
|
|
|
$htmlAttributes = $htmlOptions;
|
|
|
|
$htmlAttributes['cols'] = $cols;
|
|
|
|
$htmlAttributes['rows'] = $rows;
|
|
|
|
$str = $this->Html->textarea($tagName, $htmlAttributes);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "optional";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if ($required) {
|
|
|
|
$divClass="required";
|
|
|
|
}
|
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = sprintf("%s error", $divClass);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->divTag($divClass, $divTagInside);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function generateSelectDiv($tagName, $prompt, $options, $selected = null, $selectAttr = null, $optionAttr = null, $required = false, $errorMsg = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() or FormHelper::select() instead'), E_USER_WARNING);
|
2006-06-14 18:02:37 +00:00
|
|
|
$selectAttr['id'] = strtolower(str_replace('/', '_', $tagName));
|
|
|
|
$str = $this->Html->selectTag($tagName, $options, $selected, $selectAttr, $optionAttr);
|
2006-07-27 16:52:36 +00:00
|
|
|
$strLabel = $this->label($tagName, $prompt);
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "optional";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($required) {
|
2006-06-14 18:02:37 +00:00
|
|
|
$divClass = "required";
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$strError = "";
|
2005-12-27 03:33:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->isFieldError($tagName)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$strError = $this->Html->para('error', $errorMsg);
|
|
|
|
$divClass = sprintf("%s error", $divClass);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
$divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->divTag($divClass, $divTagInside);
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
|
|
|
* @see FormHelper::input()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function generateSubmitDiv($displayText, $htmlOptions = null) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::submit() instead'), E_USER_WARNING);
|
2006-06-19 18:18:23 +00:00
|
|
|
return $this->divTag('submit', $this->Html->submit($displayText, $htmlOptions));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* @deprecated
|
2006-12-20 21:43:11 +00:00
|
|
|
* @see FormHelper::inputs()
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function generateFields($fields, $readOnly = false) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::input() instead'), E_USER_WARNING);
|
2006-06-14 18:02:37 +00:00
|
|
|
$strFormFields = '';
|
2006-05-26 05:29:17 +00:00
|
|
|
|
|
|
|
foreach($fields as $field) {
|
2006-06-14 18:02:37 +00:00
|
|
|
if (isset($field['type'])) {
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['required'])) {
|
|
|
|
$field['required'] = false;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['errorMsg'])) {
|
|
|
|
$field['errorMsg'] = null;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['htmlOptions'])) {
|
|
|
|
$field['htmlOptions'] = array();
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if ($readOnly) {
|
|
|
|
$field['htmlOptions']['READONLY'] = "readonly";
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
switch($field['type']) {
|
|
|
|
case "input":
|
|
|
|
if (!isset($field['size'])) {
|
|
|
|
$field['size'] = 40;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateInputDiv($field['tagName'], $field['prompt'],
|
|
|
|
$field['required'], $field['errorMsg'], $field['size'], $field['htmlOptions']);
|
|
|
|
break;
|
|
|
|
case "checkbox":
|
|
|
|
$strFormFields = $strFormFields . $this->generateCheckboxDiv($field['tagName'], $field['prompt'],
|
|
|
|
$field['required'], $field['errorMsg'], $field['htmlOptions']);
|
|
|
|
break;
|
|
|
|
case "select":
|
|
|
|
case "selectMultiple":
|
|
|
|
if ("selectMultiple" == $field['type']) {
|
|
|
|
$field['selectAttr']['multiple'] = 'multiple';
|
|
|
|
$field['selectAttr']['class'] = 'selectMultiple';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['selected'])) {
|
|
|
|
$field['selected'] = null;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['selectAttr'])) {
|
|
|
|
$field['selectAttr'] = null;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['optionsAttr'])) {
|
|
|
|
$field['optionsAttr'] = null;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if ($readOnly) {
|
|
|
|
$field['selectAttr']['DISABLED'] = true;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['options'])) {
|
|
|
|
$field['options'] = null;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateSelectDiv($field['tagName'], $field['prompt'], $field['options'],
|
|
|
|
$field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg']);
|
|
|
|
break;
|
|
|
|
case "area":
|
|
|
|
if (!isset($field['rows'])) {
|
|
|
|
$field['rows'] = 10;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2006-06-14 18:02:37 +00:00
|
|
|
if (!isset($field['cols'])) {
|
|
|
|
$field['cols'] = 60;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateAreaDiv($field['tagName'], $field['prompt'],
|
|
|
|
$field['required'], $field['errorMsg'], $field['cols'], $field['rows'], $field['htmlOptions']);
|
|
|
|
break;
|
|
|
|
case "fieldset":
|
|
|
|
$strFieldsetFields = $this->generateFields($field['fields']);
|
|
|
|
$strFieldSet = sprintf(' <fieldset><legend>%s</legend><div class="notes"><h4>%s</h4><p class="last">%s</p></div>%s</fieldset>',
|
|
|
|
$field['legend'], $field['noteHeading'], $field['note'], $strFieldsetFields);
|
|
|
|
$strFormFields = $strFormFields . $strFieldSet;
|
|
|
|
break;
|
|
|
|
case "hidden":
|
|
|
|
if(!isset($field['value'])){
|
|
|
|
$field['value'] = null;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-19 18:18:23 +00:00
|
|
|
$strFormFields = $strFormFields . $this->Html->hidden($field['tagName'], $field['value']);
|
2006-06-14 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case "date":
|
|
|
|
if (!isset($field['selected'])) {
|
|
|
|
$field['selected'] = null;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateDate($field['tagName'], $field['prompt'], null,
|
|
|
|
null, null, null, $field['selected']);
|
|
|
|
break;
|
|
|
|
case "datetime":
|
|
|
|
if (!isset($field['selected'])) {
|
|
|
|
$field['selected'] = null;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateDateTime($field['tagName'], $field['prompt'], '', '', '', '', $field['selected']);
|
|
|
|
break;
|
2006-07-29 17:55:22 +00:00
|
|
|
case "time":
|
|
|
|
if (!isset($field['selected'])) {
|
|
|
|
$field['selected'] = null;
|
|
|
|
}
|
|
|
|
$strFormFields = $strFormFields . $this->generateTime($field['tagName'], $field['prompt'], '', '', '', '', $field['selected']);
|
|
|
|
break;
|
2006-06-14 18:02:37 +00:00
|
|
|
default:
|
|
|
|
break;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return $strFormFields;
|
|
|
|
}
|
2006-11-29 07:58:35 +00:00
|
|
|
/**
|
|
|
|
* @deprecated will not be available after 1.1.x.x
|
|
|
|
* @see FormHelper::label()
|
|
|
|
*/
|
|
|
|
function labelTag($tagName, $text) {
|
2006-12-22 22:49:47 +00:00
|
|
|
trigger_error(__('Deprecated: Use FormHelper::label() instead'), E_USER_WARNING);
|
2006-11-29 07:58:35 +00:00
|
|
|
return sprintf($this->Html->tags['label'], Inflector::camelize(r('/', '_', $tagName)), $text);
|
|
|
|
}
|
2006-09-29 01:32:09 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
2006-11-26 20:43:54 +00:00
|
|
|
* @see HtmlHelper::div
|
2006-09-29 01:32:09 +00:00
|
|
|
*/
|
|
|
|
function divTag($class, $text) {
|
2006-12-22 22:49:47 +00:00
|
|
|
//trigger_error(__('(FormHelper::divTag) Deprecated: Use HtmlHelper::div instead'), E_USER_WARNING);
|
2006-09-29 01:32:09 +00:00
|
|
|
return sprintf(TAG_DIV, $class, $text);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
2006-11-26 20:43:54 +00:00
|
|
|
* @see HtmlHelper::para
|
2006-09-29 01:32:09 +00:00
|
|
|
*/
|
|
|
|
function pTag($class, $text) {
|
2006-12-22 22:49:47 +00:00
|
|
|
//trigger_error(__('(FormHelper::pTag) Deprecated: Use HtmlHelper::para instead'), E_USER_WARNING);
|
2006-09-29 01:32:09 +00:00
|
|
|
return sprintf(TAG_P_CLASS, $class, $text);
|
|
|
|
}
|
2005-07-21 04:02:32 +00:00
|
|
|
}
|
2006-11-26 20:43:54 +00:00
|
|
|
|
2005-07-21 04:02:32 +00:00
|
|
|
?>
|