| 1 |
lars |
1 |
protected function processForm(sfWebRequest $request, sfForm $form)
|
|
|
2 |
{
|
|
|
3 |
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
|
|
|
4 |
if ($form->isValid())
|
|
|
5 |
{
|
|
|
6 |
$notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
|
|
|
7 |
|
|
|
8 |
try {
|
|
|
9 |
$<?php echo $this->getSingularName() ?> = $form->save();
|
|
|
10 |
} catch (Doctrine_Validator_Exception $e) {
|
|
|
11 |
|
|
|
12 |
$errorStack = $form->getObject()->getErrorStack();
|
|
|
13 |
|
|
|
14 |
$message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
|
|
|
15 |
foreach ($errorStack as $field => $errors) {
|
|
|
16 |
$message .= "$field (" . implode(", ", $errors) . "), ";
|
|
|
17 |
}
|
|
|
18 |
$message = trim($message, ', ');
|
|
|
19 |
|
|
|
20 |
$this->getUser()->setFlash('error', $message);
|
|
|
21 |
return sfView::SUCCESS;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
$this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $<?php echo $this->getSingularName() ?>)));
|
|
|
25 |
|
|
|
26 |
if ($request->hasParameter('_save_and_add'))
|
|
|
27 |
{
|
|
|
28 |
$this->getUser()->setFlash('notice', $notice.' You can add another one below.');
|
|
|
29 |
|
|
|
30 |
$this->redirect('@<?php echo $this->getUrlForAction('new') ?>');
|
|
|
31 |
}
|
|
|
32 |
else
|
|
|
33 |
{
|
|
|
34 |
$this->getUser()->setFlash('notice', $notice);
|
|
|
35 |
|
|
|
36 |
$this->redirect(array('sf_route' => '<?php echo $this->getUrlForAction('edit') ?>', 'sf_subject' => $<?php echo $this->getSingularName() ?>));
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
else
|
|
|
40 |
{
|
|
|
41 |
$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
|
|
|
42 |
}
|
|
|
43 |
}
|