Search code examples
cakephptimeinputformhelper

Is it possible to show seconds in CakePHP time input?


I have the following field: $this->Form->input('vlog_in', array('timeFormat' => '24'));

This is a 'time' field in database, so it formats the input like: 00:00 (hours:minutes).

How can i show the seconds select box, so my user can select it like 00:00:00 (hours:minutes:seconds)?


Solution

  • Just build out the form, then piece it together in the controller. I know, not as pretty as if there were just a setting for it, but...

    // VIEW
    echo $this->Form->input('vlog_in_hours', array('type' => 'select',
        'options' => array_combine(range(0,23), range(0,23)),
    ));
    echo $this->Form->input('vlog_in_minutes', array('type' => 'select',
        'options' => array_combine(range(0,59), range(0,59)),
    ));
    echo $this->Form->input('vlog_in_seconds', array('type' => 'select',
        'options' => array_combine(range(0,59), range(0,59)),
    ));
    
    
    //CONTROLLER
    function whatever() {
        //...
        $data = $this->request->data['MyModel'];
        $time = $data['vlog_in_hours'].':'.$data['vlog_in_minutes'].':'.$data['vlog_in_seconds'];
        $this->request->data['MyModel']['vlog_in'] = $time;
        //...
        $this->MyModel->save($this->request->data);
        //...
    }