Johhny P
Johhny P

Reputation: 161

modifying Form->input() data in cakePHP

A database table for Event model has following fields:

user_id, name, title

in the Event add view the user is asked to insert the name, hours and minutes as following:

    echo $this->Form->input('hours');
    echo $this->Form->input('minutes');
    echo $this->Form->input('name');

Now the name would be obviously stored as it should, but the problem occurs when I want to concacinate the hours and minutes inserted by user and store them into the DBs "title" field.

Any suggestions for how to achieve this?

Upvotes: 0

Views: 146

Answers (1)

Jon Ashdown
Jon Ashdown

Reputation: 175

use the model's beforeSave function to add any fields you like. In this case a title is being injected

in Event.php

public function beforeSave($options=array()){
  parent::beforeSave($options);
  $this->data['Event']['title'] = $this->data['Event']['hours'].$this->data['Event']['minutes'];
  //do other stuff
  return true;
} 

Upvotes: 1

Related Questions