Avoid PHP notice when validation fail

This commit is contained in:
Frederic Guillot
2017-01-22 17:06:39 -05:00
parent 91266df1c9
commit 3be442bfc5
2 changed files with 10 additions and 9 deletions

View File

@@ -60,7 +60,7 @@ class ColumnController extends BaseController
public function save() public function save()
{ {
$project = $this->getProject(); $project = $this->getProject();
$values = $this->request->getValues(); $values = $this->request->getValues() + array('hide_in_dashboard' => 0);
list($valid, $errors) = $this->columnValidator->validateCreation($values); list($valid, $errors) = $this->columnValidator->validateCreation($values);
@@ -70,18 +70,19 @@ class ColumnController extends BaseController
$values['title'], $values['title'],
$values['task_limit'], $values['task_limit'],
$values['description'], $values['description'],
isset($values['hide_in_dashboard']) ? $values['hide_in_dashboard'] : 0 $values['hide_in_dashboard']
); );
if ($result !== false) { if ($result !== false) {
$this->flash->success(t('Column created successfully.')); $this->flash->success(t('Column created successfully.'));
return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id'])), true); $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id'])), true);
return;
} else { } else {
$errors['title'] = array(t('Another column with the same name exists in the project')); $errors['title'] = array(t('Another column with the same name exists in the project'));
} }
} }
return $this->create($values, $errors); $this->create($values, $errors);
} }
/** /**
@@ -112,7 +113,7 @@ class ColumnController extends BaseController
public function update() public function update()
{ {
$project = $this->getProject(); $project = $this->getProject();
$values = $this->request->getValues(); $values = $this->request->getValues() + array('hide_in_dashboard' => 0);
list($valid, $errors) = $this->columnValidator->validateModification($values); list($valid, $errors) = $this->columnValidator->validateModification($values);
@@ -122,18 +123,19 @@ class ColumnController extends BaseController
$values['title'], $values['title'],
$values['task_limit'], $values['task_limit'],
$values['description'], $values['description'],
isset($values['hide_in_dashboard']) ? $values['hide_in_dashboard'] : 0 $values['hide_in_dashboard']
); );
if ($result) { if ($result) {
$this->flash->success(t('Board updated successfully.')); $this->flash->success(t('Board updated successfully.'));
return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id']))); $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id'])), true);
return;
} else { } else {
$this->flash->failure(t('Unable to update this board.')); $this->flash->failure(t('Unable to update this board.'));
} }
} }
return $this->edit($values, $errors); $this->edit($values, $errors);
} }
/** /**

View File

@@ -3,7 +3,6 @@
</div> </div>
<form method="post" action="<?= $this->url->href('ColumnController', 'update', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?>" autocomplete="off"> <form method="post" action="<?= $this->url->href('ColumnController', 'update', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
<?= $this->form->hidden('id', $values) ?> <?= $this->form->hidden('id', $values) ?>