Search code examples
twitter-bootstrapcakephp-2.1

How to insert html code just before <input in cakephp helper


I have this block of code in a login .ctp file:

<?php echo $this->Form->create('AdmUser', array(
    'class' => 'form-vertical',
    'inputDefaults' => array(
        'label' => false,
        'div' => false,
    ))); ?>

<?php echo $this->Form->input('login', array(
    'placeholder' => 'User')
    );?>

I'm using slywalker's TwitterBootstrap plugin for cakephp so the output is like this:

<div class="control-group">
     <div class="controls">
          <input name="data[AdmUser][login]" placeholder="User" maxlength="15" type="text" id="AdmUserLogin" required="required">
     </div>
</div>  

I'm trying to put some html code just before input tag like this:

<div class="control-group">
     <div class="controls">
          <span class="add-on"><i class="icon-user"></i></span>
          <input name="data[AdmUser][login]" placeholder="User" maxlength="15" type="text" id="AdmUserLogin" required="required">
     </div>
</div>

When i try to use 'before' => '<span class="add-on"><i class="icon-lock"></i></span>' the code goes between <div class="control-group"> and <div class="controls">


Solution

  • Have you tried the examples in the readme of the plugin?

    https://github.com/slywalker/TwitterBootstrap/blob/master/README.md

    I haven't tested it, but it seems the plugin uses 'prepend' and 'append' options to add these kind of options; if these options are set, the FormHelper internally generated these tags using this method;

    BootstrapFormHelper::addOn()