Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


enhancement acces to value in Form::config #906

agborkowski opened this Issue · 3 comments

2 participants

AgBorkowski Simon JAILLET

i want to override text template or add new template for inputs like this

$this->form->config(['templates' => [
    'text' => '<span id="{:name}">{:value}</span>', #for view mode ;)
    'span' => '<span id="{:name}">{:value}</span>'

but i dont have acces to :value any solutions ?


Imo overriding default tags are not a good idea. If you are looking for input wrapping, it's imo simpler to use Form::field() which is designed for. Either with a custom html string:

$this->form->field('name', array(
    'template' => '<span{:wrap}>{:label}: {:input}{:error}</span>'

or your custom named template string:

$this->form->field('name', array(
    'template' => 'mytext'

ok good idea, but still in template i dont have access to value of binded data

$this->form->field('name', array(
    'template' => '<span{:wrap}>{:label}: {:value}{:error}</span>'

i dont want to make for 60 inputs in form

if (isset($data) && $mode !== 'edit') {
  echo "<span><label for=\"UserProfilesName\">Name</label>";
  if(!empty($data->name)) {
    echo ": {$data->name}";
  } else {
    echo ": empty";
  echo "</span>";
} else {
  $this->form->field('name', [
    'placeholder' => $t('name surname'),
    'required' => 'required',
    'class' => 'input'
... n+60

so i trying do something that for display mode only

if ($mode === 'edit') {
  $options = [
   'input' => '<span{:wrap}>{:label}: {:value}{:error}</span><input type="hidden" value="{:value}">',
   'date' => '...',
   'email' => '...',
   'www' => '...'

i think i must extends form->field !


I don't know if it's a common enough issue to include this kind of feature in the core (only the Lead Architect knows) since uneditable inputs could be managed with the 'readonly' => 'readonly' attribute imo. And a simple overriding ead Architectof Form should work:

namespace app\extensions\helper;

class Form extends \lithium\template\Form {

    private $_strings = array(
        'plain' => '<span {:options}>{:value}</span>',

    public function plain($name, $options) {
        list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
        list($scope, $options) = $this->_options(array('value' => null), $options);
        $value = isset($scope['value']) ? $scope['value'] : '';
        return $this->_render(__METHOD__, $template, compact('options', 'value'));

Otherwise you can do a PR with your proposal ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.