Код на базе Kohana

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Add entry into DB (AJAX supported)
*
* @param: void
* @return: void
*/
public function add() {
$post = $this->input->post();
$form = View::factory('admin/add_team');
$form->action = 'none';
if(!empty($post)) {
$post = new Validation($post);
$post->pre_filter('trim');
$post->add_rules('name', 'required', 'length[2,45]');
$post->add_rules('leader', 'required', 'numeric');
$post->add_callbacks('name', array($this, '_check_name'));
if($post->validate()) {
$form->action = 'success';
$team = ORM::factory('team');
$team->name = $post->name;
$team->user_id = $post->leader;
$team->save();
} else {
$form->action = 'fail';
$form->errors = $post->errors();
}
}
if(request::is_ajax()) {
$this->auto_render = false;
$form->render(true);
} else {
$this->template->content = $form;
}
}