Welcome Guest, Not a member yet? Register   Sign In
Datamapper: Problem validation
#1

[eluser]scherman[/eluser]
Hi, i have a problem with the datamapper, and i new on that. i hope you can help me.

I have a controller's method called "create" which add an "article" object to the Database. Each article has one "Author".

The form is composed by:
- Title (input text)
- Author (dropdown: default-index = 0) -> I load the authors objects at this dropdown, so the user can chose one.

The "create" method at the controller have this:
Code:
$article = new Article();
$article->title = $this->input->post('txtTitle');

$author = new Author();
$author->where('id', $this->input->post('dpAuthor'));
$author->get();

if($article->save($author)){
    echo 'It has been added';
}else{
    echo $article->error->string;
}

Article's model (only the validation's part)
Code:
var $validation = array(
        'title' => array(
            'label' => 'Title',
            'rules' => array('required', 'trim', 'min_length' => 1, 'max_length' => 50),
        )
    );

The problem is, if i let the text field empty and chose none authors, the error is only about the title field, but it says nothing about the author field (and i have no authors with id=0)

I want that, if the user let the form empty (text's field empty, and the dropdown's index = 0), shows an error which include "complete the title" but "select an author" too.

How can i do that? I listen any others ways to do it too.

Thank you so much and sorry for my english.




Theme © iAndrew 2016 - Forum software by © MyBB