how to change name in form month

Viewed 186

I have this in my code

$this->Form->month('cc_month',['monthNames' => false]);

It generates the following code:

<select name="cc_month[month]">
    <option value="" selected="selected"></option>
    <option value="01">1</option>
    <option value="02">2</option>
    <option value="03">3</option>
    <option value="04">4</option>
    <option value="05">5</option>
    <option value="06">6</option>
    <option value="07">7</option>
    <option value="08">8</option>
    <option value="09">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
</select>

But I only want <select name="cc_month">, without the [month] prefix. How can I do that?

1 Answers

The method

Cake\View\Helper\FormHelper::month(string $fieldName, array $attributes)

is meant to be used with date related fields.

The property $fieldName will be used as a prefix for the HTML name attribute of the select element, as described in Creating Date & Time Related Controls.

In your case, I understand that field month stores an integer. You can use the following code to generate the appropriate SELECT tag:

echo $this->Form->select('cc_month',range(1,12))  
Related