I can pre-populate a form of 1 record but i cant get multiple records to pre-populate a form. I want to pre-populate all the records from an ID of which there will be about 6-10 rows.
I get the required form fields to display (about 7 records as expected) but nothing in the textboxes. The docs are not clear about multiple records in this case.
Also I need save only a few of these records
public function availtmped($id = null) {
$this->loadModel('AvailabilityForTutor');
....
if ($this->request->is('post')) {
$this->Availtmp->create();
$tutoredit = array('Availtmp' => $this->request->data['AvailablityForTutor']);
$tutoredit['Availtmp']['id']=NULL;
$tutoredit['Availtmp']['tutor_id']=$id;;
if ($this->Availtmp->save($tutoredit)) {
$this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success');
// $this->redirect(array('controller'=> 'tutors' , 'action' => 'tutordetails'));
} else {
$this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert');
}
} else {
// $this->request->data = $this->AvailablityForTutor->read(null, $id);
}
$tutor_id = $id;
$tutor =$this->AvailabilityForTutor->find('all',array( 'conditions'=>array('tutor_id'=> $tutorId)));
$this->request->data=$tutor;
view// UPDATE - I can populate with weekday but not time field as I just get the wrong start/end time
echo $this->Form->create('AvailablityForTutor', array('type' => 'post'));
foreach ($tutor as $key => $item):
echo $this->Form->input('AvailabilityForTutor.'.$key.'.weekday',
array('value'=>$this->request->data[$key] echo $this->Form->input('weekday',
array('value'=>$this->request->data[$key]['AvailabilityForTutor']['weekday']));
echo $this->Form->input('start_time',
array('value'=>$this->request->data[$key]['AvailabilityForTutor']['start_time']));
echo $this->Form->input('end_time',
array('value'=>$this->request->data[$key]['AvailabilityForTutor']['end_time']));
echo $this->Form->end('Save Edit Request');