0

I'm using form helper to input date select as follows

echo $this->Form->date('date_from', [
    'empty' => [
        'year' => 'Choose Year',
        'month' => 'Choose Month',
        'day' => 'Choose Date'
    ],
    'label' => 'Date From'
]);

But this is only showing select field and not the label Date From

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285

2 Answers2

0

It looks like CakePHP3 form helper with date doesn't support label as parameter.

But this will generate exactly the same label as you want:

<?php
  echo $this->Form->label('Date From');
  echo $this->Form->date('date_from', [
 'empty' => [
    'year' => 'Choose Year',
    'month' => 'Choose Month',
    'day' => 'Choose Date'
 ],
]);
?>

See here: Creating label in CakePHP3 form helper.

Manohar Khadka
  • 2,186
  • 2
  • 18
  • 30
  • I know we can print label this way. Can't we print label along with date or time input field? – Anuj TBE Mar 25 '17 at 13:36
  • It looks like we can't..and if you see in documentation there is no any example for using label within date and time input field. – Manohar Khadka Mar 25 '17 at 13:41
  • 1
    If you want to create labels with a single call, then you have to use the `control()` (previously `input()`) method. The type specific helper methods are explicitly ment to [**only create the input elements**](https://book.cakephp.org/3.0/en/views/helpers/form.html#generating-specific-types-of-controls). @AnujTBE – ndm Mar 25 '17 at 15:59
0

You can add the label in your HTML code:

    <div class="input date">
        <label>My label</label>
        <?php echo $this->Form->date('from_date'); ?>
    </div>

The difference between the Date Form Control and Form Control is that the last one outputs the div wrapper and the label (among others).

Saxtheowl
  • 4,136
  • 5
  • 23
  • 32