[eluser]scherman[/eluser]
Hi, i am developing a backend, and i am new at Datamapper.
I have this:
- Class Author (has many articles)
- Class Article (has one author)
I am working on the article's edition. And i have a problem with the validation
The validation of the Article's class is:
Code:
var $validation = array(
'title' => array(
'label' => 'Title',
'rules' => array('required', 'trim', 'min_length' => 1, 'max_length' => 50)
),
'author' => array(
'label' => 'Author',
'rules' => array('required')
)
);
In the form i have two fields:
- Title (Textbox)
- Author (dropdown with the default-index: 0)
When i, as application's user, create an article, for example, if i complete the title's field but i leave the author empty (dropdown's index = 0), it returns me the error.
But when i am editing an article, if i leave the author's field empty, it doesn't return me an error, and it saves the article with no author.
Here is the code of edit's method (only the save's part):
Code:
$article = new Article();
$article->where('id', $id)->get();
$article->title = $this->input->post('txtTitle');
$author = new Author();
$author->where('id', $this->input->post('cmbAuthor'))->get();
if($article->save($author)){
//Shows success message
}else{
//Shows error messages
}
I hope you can help me, because i got stuck here.
Happy christmas =)