Esempio n. 1
0
/**
 * Sets field defaults and adds field to form security input hash.
 * Will also add a 'form-error' class if the field contains validation errors.
 *
 * ### Options
 *
 * - `secure` - boolean whether or not the field should be added to the security fields.
 *   Disabling the field using the `disabled` option, will also omit the field from being
 *   part of the hashed key.
 *
 * This method will convert a numerically indexed 'disabled' into a associative
 * value. FormHelper's internals expect associative options.
 *
 * @param string $field Name of the field to initialize options for.
 * @param array $options Array of options to append options into.
 * @return array Array of options for the input.
 */
	protected function _initInputField($field, $options = array()) {
		if (isset($options['secure'])) {
			$secure = $options['secure'];
			unset($options['secure']);
		} else {
			$secure = (isset($this->request['_Token']) && !empty($this->request['_Token']));
		}

		$disabledIndex = array_search('disabled', $options, true);
		if (is_int($disabledIndex)) {
			unset($options[$disabledIndex]);
			$options['disabled'] = true;
		}

		$result = parent::_initInputField($field, $options);
		if ($this->tagIsInvalid() !== false) {
			$result = $this->addClass($result, 'form-error');
		}
		if (!empty($result['disabled']) || $secure === self::SECURE_SKIP) {
			return $result;
		}
		if (!isset($result['required']) &&
			$this->_introspectModel($this->model(), 'validates', $this->field())
		) {
			$result['required'] = true;
		}

		$this->_secure($secure, $this->_secureFieldName($options));
		return $result;
	}
Esempio n. 2
0
 /**
  * Sets field defaults and adds field to form security input hash
  *
  * ### Options
  *
  *  - `secure` - boolean whether or not the field should be added to the security fields.
  *
  * @param string $field Name of the field to initialize options for.
  * @param array $options Array of options to append options into.
  * @return array Array of options for the input.
  */
 protected function _initInputField($field, $options = array())
 {
     if (isset($options['secure'])) {
         $secure = $options['secure'];
         unset($options['secure']);
     } else {
         $secure = isset($this->request['_Token']) && !empty($this->request['_Token']);
     }
     $fieldName = null;
     if ($secure && !empty($options['name'])) {
         preg_match_all('/\\[(.*?)\\]/', $options['name'], $matches);
         if (isset($matches[1])) {
             $fieldName = $matches[1];
         }
     }
     $result = parent::_initInputField($field, $options);
     if ($secure) {
         $this->__secure($fieldName);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Sets field defaults and adds field to form security input hash
  *
  * Options
  *
  *  - `secure` - boolean whether or not the the field should be added to the security fields.
  *
  * @param string $field Name of the field to initialize options for.
  * @param array $options Array of options to append options into.
  * @return array Array of options for the input.
  * @access protected
  */
 function _initInputField($field, $options = array())
 {
     if (isset($options['secure'])) {
         $secure = $options['secure'];
         unset($options['secure']);
     } else {
         $secure = isset($this->params['_Token']) && !empty($this->params['_Token']);
     }
     $result = parent::_initInputField($field, $options);
     if ($secure) {
         $this->__secure();
     }
     return $result;
 }
 /**
  * Sets field defaults and adds field to form security input hash
  *
  * ### Options
  *
  * - `secure` - boolean whether or not the field should be added to the security fields.
  *   Disabling the field using the `disabled` option, will also omit the field from being
  *   part of the hashed key.
  *
  * @param string $field Name of the field to initialize options for.
  * @param array $options Array of options to append options into.
  * @return array Array of options for the input.
  */
 protected function _initInputField($field, $options = array())
 {
     if (isset($options['secure'])) {
         $secure = $options['secure'];
         unset($options['secure']);
     } else {
         $secure = isset($this->request['_Token']) && !empty($this->request['_Token']);
     }
     $result = parent::_initInputField($field, $options);
     if ($this->tagIsInvalid() !== false) {
         $result = $this->addClass($result, 'form-error');
     }
     if (!empty($result['disabled']) || $secure === self::SECURE_SKIP) {
         return $result;
     }
     $fieldName = null;
     if (!empty($options['name'])) {
         preg_match_all('/\\[(.*?)\\]/', $options['name'], $matches);
         if (isset($matches[1])) {
             $fieldName = $matches[1];
         }
     }
     $this->_secure($secure, $fieldName);
     return $result;
 }
Esempio n. 5
0
 /**
  * Sets field defaults and adds field to form security input hash.
  * Will also add a 'form-error' class if the field contains validation errors.
  *
  * ### Options
  *
  * - `secure` - boolean whether or not the field should be added to the security fields.
  *   Disabling the field using the `disabled` option, will also omit the field from being
  *   part of the hashed key.
  *
  * This method will convert a numerically indexed 'disabled' into an associative
  * value. FormHelper's internals expect associative options.
  *
  * @param string $field   Name of the field to initialize options for.
  * @param array  $options Array of options to append options into.
  *
  * @return array Array of options for the input.
  */
 protected function _initInputField($field, $options = array())
 {
     if (isset($options['secure'])) {
         $secure = $options['secure'];
         unset($options['secure']);
     } else {
         $secure = isset($this->request['_Token']) && !empty($this->request['_Token']);
     }
     $disabledIndex = array_search('disabled', $options, TRUE);
     if (is_int($disabledIndex)) {
         unset($options[$disabledIndex]);
         $options['disabled'] = TRUE;
     }
     $result = parent::_initInputField($field, $options);
     if ($this->tagIsInvalid() !== FALSE) {
         $result = $this->addClass($result, 'form-error');
     }
     $isDisabled = FALSE;
     if (isset($result['disabled'])) {
         $isDisabled = $result['disabled'] === TRUE || $result['disabled'] === 'disabled' || is_array($result['disabled']) && !empty($result['options']) && array_diff($result['options'], $result['disabled']) === array();
     }
     if ($isDisabled) {
         return $result;
     }
     if (!isset($result['required']) && $this->_introspectModel($this->model(), 'validates', $this->field())) {
         $result['required'] = TRUE;
     }
     if ($secure === static::SECURE_SKIP) {
         return $result;
     }
     $this->_secure($secure, $this->_secureFieldName($options));
     return $result;
 }