We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

SetValue for DateField Form Element | Forum

Guna
Guna Apr 13 '15
I need to show the current date selected in the datefield  of form.


I tried the below code.


$currentDate = date(strtotime(time()));
$date = new DateField('date');


$date->setLabel($this->text('enquiry','enquiry_start_date'));


if(isset($_SESSION["session1"]))

{

     $date->setValue($currentDate);

}

$form->addElement($date);


But When I see the form in the front end, The current date is not chosen.


How to do this? 


I think this is not a custom code modification. Moderators Please explain if you think this is a custom code modification.



The Forum post is edited by Guna Apr 13 '15
dave Leader
dave Apr 16 '15
$date = date("Ymd");
Guna
Guna Apr 21 '15
@dave. Thanks for the reply. But that didn't work for me.


The below code is worked fine for me.


$date_value = date('Y', date(strtotime($date_value->dob))) . '/' . date('n', date(strtotime($date_value->dob))) . '/' . date('j',date(strtotime($date_value->dob)));
$date = new DateField('date');$date ->setValue(date($date_value));

$form->addElement($date);