Reputation: 305
I'm trying to format my input without any success. I need to save mp3 to my table with the duration of each audio file. For that, I would like to have an input that allows me to choose hours:minutes:seconds. The field for the duration in my table is TIME, I don't need a dateTime for that I guess.
So here is what I've done that doesn't work:
<?php echo $this->Form->input('duration', array('type' => 'time', 'label' => 'Durée piste', 'dateFormat' => 'H:i:s')); ?>
Does anyone knows how to do that? Thanks in advance!
Upvotes: 0
Views: 2573
Reputation: 428
Just Replace your old arrays with these new arrays.
$hours=array();
for($a=0; $a < 2; $a++){
for($b=0; $b < 10; $b++){
if ($a.$b == 13) {
break;
}
$hours[$a.$b]=$a.$b;
}
}
$ms=array();
for($a=0; $a < 6; $a++){
for($b=0; $b < 10; $b++){
$ms[$a.$b]=$a.$b;
}
}
Upvotes: 0
Reputation: 428
If you are not a php expert then you can go with simple code given below.
Note: Post is my Model name.So Replace it with yours.
Add function in your controller
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
$hours = $this->data['Post']['hours'];
$minutes = $this->data['Post']['minutes'];
$seconds = $this->data['Post']['seconds'];
$this->request->data['Post']['duration']=$hours.':'.$minutes.':'.$seconds;
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your post.');
}
}
}
Code in add.ctp file
$hours=array();
for($i=0;$i<13;$i++){
$hours[$i]=$i;
}
$ms=array();
for($i=0;$i<60;$i++){
$ms[$i]=$i;
}
echo $this->Form->input('hours',array('type' => 'select', 'options' => $hours));
echo $this->Form->input('minutes',array('type' => 'select', 'options' => $ms));
echo $this->Form->input('seconds',array('type' => 'select', 'options' => $ms));
Upvotes: 3