function edit()
{
$additionals =
$this->Additional->getAdditionals($this->Auth->User('id'));
if (!empty($this->data)) {
debug($this->data);
$this->Additional->deleteAll(array('Additional.profile_id' =>
$this->Auth->User('id')));
foreach ($this->data['Additional'] as $key =>
$value) {
//if name is empty remove skill
if (empty($value['name'])) {
//debug($value);
unset($this->data['Additional'][$key]);
}
}
debug($this->data);
foreach ($this->data['Additional'] as
$entry) {
//debug($entry);
$this->Additional->create();
$this->data['Additional']['profile_id'] =
$this->Auth->User('id');
$this->data['Additional']['name'] = $entry['name'];
$this->data['Additional']['skillset_id'] =
$entry['skillset_id'];
$this->data['Additional']['year_id'] =
$entry['year_id'];
$this->Additional->save($this->data, true);
}
if ($this->Additional->saveAll($this->data,
array('validate'=>'first'))) {
$this->Session->setFlash(__('The Additional has been
saved', true));
} else {
$this->Session->setFlash(__('The Additional could not
be saved. Please, try again.', true));
}
}
$skillsets = $this->Additional->Skillset->find('list',
array('conditions' => array('Skillset.id !=' => 8),'fields' =>
array('Skillset.id', 'Skillset.group')));
$years = $this->Additional->Year->find('list',
array('fields' => array('Year.id', 'Year.range')));
$this->set(compact('skillsets', 'years', 'additionals'));
}
$this->Additional->getAdditionals produces:
Array
(
[Additional] => Array
(
[0] => Array
(
[id] => 19
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdf
[created] =>
[modified] =>
)
[1] => Array
(
[id] => 20
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdf
[created] =>
[modified] =>
)
[2] => Array
(
[id] => 21
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdfsdf
[created] =>
[modified] =>
)
[3] => Array
(
[id] => 22
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdfsdf
[created] =>
[modified] =>
)
[4] => Array
(
[id] => 23
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdfsdf
[created] =>
[modified] =>
)
[5] => Array
(
[id] => 24
[profile_id] => 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
[skillset_id] => 1
[year_id] => 1
[name] => sdfsdfsdf
[created] =>
[modified] =>
)
)
)
So this is the data that now gets saved and pulled from the db. I just cant
get it populated into the fields.
Thanks again for your time.
Dave
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of John Andersen
Sent: January-06-10 5:14 PM
To: CakePHP
Subject: Re: Form Fields
Ok, I see I answered something in your Add fields thread which you are
actually doing here :) Please show the code that you are using for the save
operation, also what you are doing with the data before the save operation.
Enjoy,
John
On Jan 6, 9:42 pm, "Dave" <[email protected]> wrote:
> Ok i make my 10 additional fields with this in my edit form:
>
> <?php $i=0;
> while($i<=9)
> {
> echo $form->input('Additional.'.$i.'.skillset_id', array('label'
> => 'Select skill:'));
> echo $form->input('Additional.'.$i.'.year_id', array('label' =>
> 'Select experience range:'));
> echo $form->input('Additional.'.$i.'.name', array('label' =>
> 'Skill name:'));
>
> $i++;
> }
> ?>
>
> So i submit an end up with this array: (debug data before save)
>
> Array
> (
> [Additional] => Array
> (
> [0] => Array
> (
> [skillset_id] => 3
> [year_id] => 1
> [name] =>
> )
>
> [1] => Array
> (
> [skillset_id] => 1
> [year_id] => 3
> [name] =>
> )
> .............. Thru 9 plus [0] = 10
> [9] => Array
> (
> [skillset_id] => 1
> [year_id] => 1
> [name] =>
> )
> )
>
> )
> There is no add function since the edit form holds the 10 fields only
> tht they can work with so fill in 1 or all 10 and that's what you get.
>
> So after clicking save the array above shows what would be saved,
> below is what gets pulled from the db I added maually to the db, not
> thru the form The data I pull from the db comes back in this format
> but the fields are never populated with the user data from the db.
>
> Array
> (
> [Additional] => Array
> (
> [0] => Array
> (
> [id] => 66
> [profile_id] =>
> 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
> [skillset_id] => 1
> [year_id] => 1
> [name] => Test 1
> [created] =>
> [modified] =>
> )
>
> [1] => Array
> (
> [id] => 67
> [profile_id] =>
> 4b40eea7-2608-4a3b-9c24-7cb04adcd75b
> [skillset_id] => 2
> [year_id] => 2
> [name] => test 2
> [created] =>
> [modified] =>
> )
> )
>
> )
>
> Can someone see where I am going wrong here?
>
> Thanks
>
> Dave
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.725 / Virus Database: 270.14.124/2599 - Release Date: 01/06/10
04:05:00
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en