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 8272867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:16:32+00:00 2026-06-08T07:16:32+00:00

I have a page, where user can edit his own info. On this page

  • 0

I have a page, where user can edit his own info. On this page there are also 3 dropdown lists for birth date (date, month, year). But I have only one column for birth date in my table, which accepts value in format “ddmmyyyy”
How can I render these 3 fields in CActiveForm, so they together fill one complete value, like “ddmmyyyy”?
Thank you.
Update:
Model code:

public $day;
public $month;
public $year;

public function getDates()
{
     return array(
       20=>20,
       21=>21,
    );
}
public function getMonth()
{
     return array(
       01=>01,
       02=>02,
    );
}
public function getYears()
{
     return array(
       1990=>1990,
       1991=>1991,
    );
}

Controller code:

if(isset($_POST['User']))
            {
                $user->attributes=$_POST['User'];
                $user->day = $_POST['User']['day'];
                $user->month = $_POST['User']['month'];
                $user->year = $_POST['User']['year'];
                $date = $user->day . $user->month . $user->year;
                $user->birthday = $date;
                if($user->save())
                    $this->redirect('/user/index');
            }

View code:

                <div class="day">
                    <?php echo $form->dropDownList($user,'day', $user->getDates()); ?>
                </div>
                <div class="month">
                    <?php echo $form->dropDownList($user,'month', $user->getMonth()); ?>
                </div>
                <div class="year">
                    <?php echo $form->dropDownList($user,'year', $user->getYears()); ?>
                </div>
  • 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-08T07:16:34+00:00Added an answer on June 8, 2026 at 7:16 am

    In your model class create these 3 properties by hand. On your form you will reference just these three properties. You will make use of the events to wrap your database column values to these three fields like this:

    In afterFind(), make sure you have code that will split the database column property in all these three.

    In beforeValidate() make sure you have code that will take these three properties and join together in the database column property.

    Add the necessary validation to the rules() and labels to attributes().

    Update

    First of all some changes

    $user->attributes=$_POST['User'];
    $user->day = $_POST['User']['day'];
    $user->month = $_POST['User']['month'];
    $user->year = $_POST['User']['year'];
    

    you don’t need all the assignments if you add the day, month, year attribute to the ‘safe’ list. Read more at Understanding safe validation rules.

    Move this code to the model class:

    protected function beforeValidate()
    {
       $this->birthday = $this->day . $this->month . $this->year;
       return parent::beforeValidate();
    }
    

    Make sure you call validation to validate the form:

    if($user->validate() && $user->save())
             $this->redirect('/user/index');
    

    add code to afterFind() that is reverse to beforeValidate() as

    protected function afterFind()
    {
        $this->day= ...get day part from $this->birthday...
        $this->month=
        $this->year=
        return parent::afterFind();
    }
    

    You don’t need all those getMonth() functions. You can use the range or the array_fill functions from PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page where the user can edit various content using buttons and
I have this PHP page where the user can select and un-select items. The
I've got a user page, where user can change his settings ( users#edit ).
I have a page where a user can import data to the site. either
I have a page where the user can dynamically add file upload boxes. Adding
I have a page where a user can upload a file along with some
I have a page which contains a dynamically generated grid, where a user can
I have a form on a page that a user can use to create
I have a section on a page where a user can change their username.
I have a list of items on my web page that the user can

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.