0

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">

2 Answers 2

1

I have tested my code to the CakePhp version cakephp-2.6.6.

echo $this->Form->input(
    'login', 
    array(
    'between' =>'<span class="add-on"><i class="icon-lock"></i></span>',
    'after'=>'',
    'placeholder' => 'User'
    )
);

And which produces:

<span class="add-on"><i class="icon-lock"></i></span>
<input type="text" id="AdmUserLogin" placeholder="User" name="data[AdmUser][login]">

You have custom form helper I think that's why you got

<div class="control-group">
     <div class="controls">

Code before input field and your 'before' tag not working.If you add 'between' tag it will add code before your input and finally you have to add 'after' tag to null because you do not need to add extra html after your input field. Thanks.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Thanks, that's the answer that solves my problem, just adding 'prepend' => '<i class="icon-user"></i>' in the options array of the Form->input, generates the code the way i want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.