Indzi
Indzi

Reputation: 390

CakePHP: FormHelper Timefield not inserting any data

The formHelper For time is not inserting data to the database:

+---------------------------------------------------+
|attendence_id|id   |in_time    |out_time|date.     |
+---------------------------------------------------+
|15           |4    |00:00:30   |00:00:30|2014-04-12|
+---------------------------------------------------+

My View

<div class="index">
 <?php
 echo $this->Form->create('Employee In Time');
 echo $this->Form->input('Employee ID',array("name"=>"id"));
 echo $this->Form->input('In Time', array(
     'name' => 'in_time',
     'timeFormat' => '24',
     'type' => 'time',
     'selected' => '09:30:00'
 ));

 echo $this->Form->input('Out Time', array(
     'name' => 'out_time',
     'timeFormat' => '24',
     'type' => 'time',
     'selected' => '09:30:00'
 ));


 echo $this->Form->input('Date Insert in Y/M/D', array(
    'name' => 'date',
    'dateFormat' => 'YMD',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18 ));

 echo $this->Form->end('Add');
?>
</div>

<div class="actions">
    <h3>Actions</h3>
    <ul>
        <li><a href="/users/add">New Employee</a></li>
        <li><a href="/user_types">Attendance</a></li>
        <li><a href="/users/add">Salary Calculator</a></li>
        </ul>
</div>

My Model

class Attendence extends AppModel {


    function add($data){
        if (!empty($data)) {
            $this->create();
            if($this->save($data)) {
                return true ;

            }
        }
    }

My Controller

class AttendencesController extends AppController {

public function intime()
{


    if($this->Attendence->add($this->request->data)==true){
        $this->redirect(array('action'=>'intime'));
    }


}

}

Please Help

Upvotes: 0

Views: 72

Answers (1)

Simon
Simon

Reputation: 4794

Take attention on CakePHP´s code convention:

The first parameter of echo $this->Form->create('Model'); is the model name, the view is related to. Replace your Employee in Time by your model´s name: echo $this->Form->create('Attendence');

I suggest to put your model´s code into the controller:

class AttendencesController extends AppController 
{  
    public function intime()
    {
        if($this->request->is('post','put'))
        {
            $this->Attendence->create();

            if($this->Attendence->save($this->request->data))
            {
                $this->redirect(array('action'=>'intime'));
            }
        }     
    }   
}

Upvotes: 1

Related Questions