Reputation: 17
so I have a Tarif, which hasMany Price (each for different currency - doesn't really matter)
the view (deleted irrelevant parts)
<?php echo $this->Form->create('Tarif');
echo $this->Form->input("Price.0.price");
echo $this->Form->input("Price.0.currency");
echo $this->Form->input("Price.0.sms_format");
echo $this->Form->input("Price.0.sms_number");
echo $html->link(__('Add currency', true), '#', array('onclick'=>'return false;', 'class' => 'tarifs-add-currency'));
echo $this->Form->input('Tarif.valid_since', array('timeFormat' => '24'));
echo $this->Form->input('Tarif.valid_until', array('timeFormat' => '24'));
echo $this->Form->input('Tarif.storage_time', array('label' => __('Storage time (days)', true)));
echo $this->Form->end(__('Submit', true));?>
The controller function to save it looks like this
function admin_add() {
if (!empty($this->data)) {
$this->Tarif->create();
if ($this->Tarif->saveAll($this->data)) {
$this->Session->setFlash(__('The tarif has been saved', true));
$this->redirect(array('action' => 'admin_index'));
} else {
$this->Session->setFlash(__('The tarif could not be saved. Please, try again.', true));
}
}
}
The "add currency" link is there to add new inputs for new prices, but that isn't the problem, because it doesn't work even without adding currencies. When I try to save it, it says 'The tarif could not be saved. Please, try again.'. Don't you know what should I change in order to make it work?
Thanks EL
Upvotes: 0
Views: 2681
Reputation: 6047
For me this look like you have validation problem - check if in your models you have some validation rules on fields which are not in the form. For example if you have a field user_id in the table and if you build your model with the bake console it's possible this field to be created as numeric.
This way even it's not in the form it's validated and the form return false. Try to print $this->YourModel->validationErrors and see if there is something there.
Another hint - have you use by any chance beforeSave() and beforeValidate() in your model? If so, they need to return bool true otherwise the save function can return false as well and it wont save anything.
Upvotes: 2