0
<?=
$this->Form->input('username', [
    'label' => false,
    'placeholder' => __('Username or email address'),
    'class' => 'form-control'
])
?>

How I add svg to this function?

svg code:

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
karel
  • 5,489
  • 46
  • 45
  • 50
S. Osher
  • 1
  • 1

1 Answers1

0

You cannot do this with the default form input template. You can customise your form input template as below in order to achieve this.

     <?php 
        echo $this->Form->input('username', [
            'label' => false,
            'placeholder' => __('Username or email address'),
            'class' => 'form-control',
            'templates' => [
                            'inputContainer' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>{{content}}'
             ],
        ])
        ?>

Reference: Cakephp -> Form -> Customizing the Templates FormHelper Uses

Sehdev
  • 5,486
  • 3
  • 11
  • 34
  • hi i tried to do that but is not containing in the same div, is creating anthor div this is a picture what i want https://prnt.sc/n007tf – S. Osher Mar 19 '19 at 14:07
  • Then this is nothing to do with Cakephp. you have to do this with css. For e.g https://stackoverflow.com/questions/917610/put-icon-inside-input-element-in-a-form https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_form_icon – Sehdev Mar 19 '19 at 15:49