eithelruin
(Eithelruin)
January 30, 2011, 9:14pm
1
Hi all,
I am fairly new to Yii and I am trying to use it for some web forms.
I have installed the EHtmlDateSelect widget and I get it to display what I want and how I want it. However, when time comes to save back to the database, nothing happens. If I was editing an old value, the old value is preserved and if I try to insert a new value, nothing happens. Here’s the code in my view:
<div class="row">
<?php echo $form->labelEx($model,'DOB'); ?>
<?php $this->widget('application.extensions.EHtmlDateSelect',
array(
'time' => $model->DOB,
'prefix' => '',
'field_order' => 'DMY',
'start_year' => '1850',
'end_year' => '+1',
));
?>
<?php echo $form->error($model,'DOB'); ?>
</div>
kosenka
(Kosenka)
March 4, 2011, 11:54am
2
Hi all,
I am fairly new to Yii and I am trying to use it for some web forms.
I have installed the EHtmlDateSelect widget and I get it to display what I want and how I want it. However, when time comes to save back to the database, nothing happens. If I was editing an old value, the old value is preserved and if I try to insert a new value, nothing happens. Here’s the code in my view:
<div class="row">
<?php echo $form->labelEx($model,'DOB'); ?>
<?php $this->widget('application.extensions.EHtmlDateSelect',
array(
'time' => $model->DOB,
'prefix' => '',
'field_array'=>'ItemsDate', <-- THIS IMPORTANT !!!!
'field_order' => 'DMY',
'start_year' => '1850',
'end_year' => '+1',
));
?>
<?php echo $form->error($model,'DOB'); ?>
</div>
Since this extension does not work with the database, then you are required to submit data from this extension to the database. For example:
public function actionEdit()
{
$model->load...
$dateForDatabase=$this->getDateFrom_EHtmlDateSelect( $_POST['ItemsDate'] );
$model->date= $dateForDatabase;
$model->save();
}
protected function getDateFrom_EHtmlDateSelect($data)
{
if(empty($data['Month'])) $data['Month']=date('m');
if(empty($data['Day'])) $data['Day']=date('d');
if(empty($data['Year'])) $data['Year']=date('Y');
if(empty($data['Hour'])) $data['Hour']=date('H');
if(empty($data['Minute'])) $data['Minute']=date('i');
if(empty($data['Second'])) $data['Second']=date('s');
return mktime(
$data['Hour'],
$data['Minute'],
$data['Second'],
$data['Month'],
$data['Day'],
$data['Year']
);
}
kosenka:
Since this extension does not work with the database, then you are required to submit data from this extension to the database. For example:
public function actionEdit()
{
$model->load...
$dateForDatabase=$this->getDateFrom_EHtmlDateSelect( $_POST['ItemsDate'] );
$model->date= $dateForDatabase;
$model->save();
}
protected function getDateFrom_EHtmlDateSelect($data)
{
if(empty($data['Month'])) $data['Month']=date('m');
if(empty($data['Day'])) $data['Day']=date('d');
if(empty($data['Year'])) $data['Year']=date('Y');
if(empty($data['Hour'])) $data['Hour']=date('H');
if(empty($data['Minute'])) $data['Minute']=date('i');
if(empty($data['Second'])) $data['Second']=date('s');
return mktime(
$data['Hour'],
$data['Minute'],
$data['Second'],
$data['Month'],
$data['Day'],
$data['Year']
);
}
I’m just a newbie… i have the same problem too but i don’t know where to start… can you please give a more detailed example… like step by step. thanks is advance