0

I am trying to achieve the output where I have a wrapper div which contains a label and an inner div, and within the inner div I have the form input.

My output should look like this:

<div class="form-group">
  <label>Name:</label>
  <div class="form-input">
    <input type="text" />
  </div>
</div>

Here is my current form object in php:

echo $this->Form->input('name', array(
    'class' => 'form-input',
    'div' => 'form-group',
    'label' => array('class' => 'control-label')));

But this adds the class form-input to the actual input itself. How would I be able to achieve this while still keeping true to the CakePHP way of doing things?

TIA!

2 Answers 2

0

Use input options 'before', 'after', 'between' http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options I haven't verified it, but I think it should look something like this:

echo $this->Form->input('name', array(
    'between' => '<div class="form-input">',
    'after' => '</div>',
    'div' => 'form-group',
    'label' => array('class' => 'control-label')));
Sign up to request clarification or add additional context in comments.

Comments

0

What about this:

echo $this->Form->input('name', array(
 'div' => 'form-group',
 'before' => '<div class="form-input">',
 'after' => '</div>',
 'label' => array('class'=>'control-label')
));

I think this works.

1 Comment

Thanks for your suggestion, however I had to use "between" instead of before

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.