€urrency in form fields

Not a matter of life and death, but it would be nice to customize the field form with a currency character ($,€ etc.). I couldn’t find the option to edit a specific form’s layout, my best guess was trying via the setTemplate option:

$this->Form->setTemplates([
    'inputContainer' => '<div class="input {{help}}{{type}}{{required}}">
        {{help}} {{content}} <span class="help">{{help}}</span></div>'
]);

Form->control('X', [.., 'templateVars'=>['help'=>'€'] ]

This prints the € sign everywhere but inside or directly in front of the form :slight_smile:

Simply without CakePHP specific commands doesn’t work either:
echo ('€ ' .$this->Form->control()'; to achieve http://jsfiddle.net/uzbjve2u/

Then the question is: how to access forms layout in order to do the above, or through CSS?

How about just breaking the form rendering apart into the individual controls - https://book.cakephp.org/4/en/views/helpers/form.html

then just build your HTML around the controls as required.

I am not sure what you explictely refer to. I have posted this question after reading the Form documentation, and I found it impossible to get the prefered design with or next to the individual controls.

When you run the code as you’ve shown above, what does the resulting HTML look like?

echo (‘€’.$this->Form->control(…) ); leads to
image

And with the templateVars:
image

I think you want to use the input template, not the inputContainer. The {{content}} part of the container template will include the label, the input, and maybe some other things.

So I should template the {{content}}? I don’t understand the template<->Form syntax, I should probably leave it for now then.

$this->Form->setTemplates([
‘input’ => '{{sign}} {{content}} ’

removes the input field and creates HTML:
image

The input template doesn’t have a {{content}} placeholder. See the full list.