Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:13:28+00:00 2026-06-16T15:13:28+00:00

Cake 2.2.4 I have a database sport_year field set to the YEAR data type.

  • 0

Cake 2.2.4

I have a database sport_year field set to the YEAR data type.
I’ve tried two approaches to creating a year menu for my add/edit views, but both have their own problems.

Using $this->Form->input:

echo $this->Form->input('sport_year', array(
    'type' => 'date',
    'dateFormat' => 'Y',
    'name' => 'data[Sport][sport_year]',
    'minYear' => date('Y') - 2,
    'maxYear' => date('Y') + 1,
    'label' => 'Year',
    'empty' => '- select -'
));

The code works fine to add or edit data (as does the validation), but when arriving at the edit page existing year data is not properly selected in the form. The data array does show [sport_year] => 2012, but 2012 is not selected in the menu.

echo $this->Form->year(
    'sport_year', 
    date('Y') - 2, 
    date('Y') + 1, 
    array(
        'name' => 'data[Sport][sport_year]', 
        'label' => 'Year', 
        'empty' => '- select -'
    )
);

The year helper seems to correctly retrieve and select the existing data, but the label does not work, and it doesn’t correctly render the field as required even though my Model has validation set. It does still require the data, but it ignores my Model custom message and is falling back to a save error message in my controller.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:13:29+00:00Added an answer on June 16, 2026 at 3:13 pm

    $this->Form->year() will never show a label. Only $this->Form->input() adds labels as it is a wrapper method and year() is for creating a year field.

    The code in cake is something like:

    public function input() {
        echo '<div>';
        echo $this->label(...);
        echo $this->year(...);
        echo '</div>';
    }
    

    Taking this code, you do not need name as cake will be generating that already. If you are not in the Sport model you can use input('Sport.sport_year', ...)

    If you read the docs you should see there is a default option for inputs. you can use that or make sure that $this->request->data['Sport']['sport_year'] is set to the year you want.

    You could also set the value option.

    echo $this->Form->input('sport_year', array(
        'type' => 'date',
        'dateFormat' => 'Y',
        'minYear' => date('Y') - 2,
        'maxYear' => date('Y') + 1,
        'label' => 'Year',
        'empty' => '- select -',
        'default' => date('Y')
    ));
    

    or

    echo $this->Form->input('sport_year', array(
        'type' => 'date',
        'dateFormat' => 'Y',
        'minYear' => date('Y') - 2,
        'maxYear' => date('Y') + 1,
        'label' => 'Year',
        'empty' => '- select -',
        'value' => date('Y')
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my database, and used cake bake my_project to create my project,
I have a Cake website and it needs to have two separate logins, each
I have two tables 1: itemInfo product_id brand name category 1 Garden Goodcake cake
I have ubuntu 10.04 on server. I am trying to set up the cake
I have function which selects data from MySQL database: function get_articles( $id ){ global
I have to use MS SQL Server 2008 to store data of PHP CAKE
Hey we have three tables in our database which are connected through two relationships
if i have a cake php saveAll method like so: if ($this->Video->saveAll($this->data)){ ... //
I have an existing database I'm trying to put a cake app on top
I have trouble saving my date field into database using CakePHP. Table column name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.