0

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?

1 Answer 1

1

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;
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.