cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Phalcon\Forms\Form::label() extra param

Open anggiaj opened this issue 13 years ago • 5 comments

\Phalcon\Forms\Form::label(string $name) according to the doc, "Generate the label of a element added to the form including HTML"

I think it's need to have extra $attributes param, because it's mean to render HTML, so it will be consistent with render method.

ex:

$form->label('name', array('class' => 'form-control'));

but right now, what i have to do...

<label for="name" class="form-control"><?=$form->getLabel('name'); ?></label>

CMIIW

anggiaj avatar Aug 08 '13 05:08 anggiaj

Test it, Indeed return label tag:

<?php
use Phalcon\Forms\Form,
    Phalcon\Forms\Element\Text,
    Phalcon\Forms\Element\Select;

$form = new Form();
$form->add(new Text("telephone", array(
    'maxlength' => 30,
    'placeholder' => 'Type your name'
)));

$text = $form->get('telephone');

echo $form->label('telephone');
echo PHP_EOL;
echo $form->getLabel('telephone');
echo PHP_EOL;
echo $text->getName();

output:

<label for="telephone">telephone</label>
telephone
telephone

dreamsxin avatar Aug 08 '13 09:08 dreamsxin

This is implemented in 1.3.0

ghost avatar Sep 25 '13 15:09 ghost

Using this, how does one generate a label as <label for="telephone">Enter your number:</label> instead of <label for="telephone">telephone</label>

PersyJack avatar Dec 01 '14 00:12 PersyJack

@PersyJack

echo $text->setLabel('Enter your number:');

dreamsxin avatar Dec 01 '14 00:12 dreamsxin

@dreamsxin Thank you, I was studying Vokuro and I tried adding 'text' => 'Enter phone number' to login controller where it has

$email = new Text('email', array(
            'placeholder' => 'Email'
        ));

but that just added a text attribute to the input. After your reply, I found that it was setup up that way in signup controller. Thank you again

PersyJack avatar Dec 01 '14 01:12 PersyJack