Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

enhancement acces to value in Form::config #906

agborkowski opened this Issue Apr 25, 2013 · 5 comments


None yet
3 participants

agborkowski commented Apr 25, 2013

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 ?


jails commented Apr 25, 2013

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'

agborkowski commented Apr 25, 2013

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 !


jails commented Apr 30, 2013

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 ;-)


davidpersson commented May 7, 2015

I'm closing this ticket as the following code does the trick without us needing to add additional code to the core:

$this->form->field('name', [
     'readonly' => !$isEditMode
/* make input appear as text */
input[readonly] {
  border: none;
  background: white;
  padding: 0;

Alternatively subclass the form helper as @jails suggested.


agborkowski commented May 31, 2015

🍻 thanx guys for give alternatives ! @jails i did it like u propose!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment