How can I retrieve an array in Simple MVC Framework to show error messages if some input fields are not valid?
Controller:
public function index($error)
{
$data ['title'] = $this->language->get('welcome_text');
View::renderTemplate('header', $data);
View::render('insert/form', $data);
View::renderTemplate('footer', $data);
}
public function save()
{
if (isset($_POST)) {
$data ['is_valid'] = \Helpers\Gump::is_valid($_POST, array(
'firstname' => 'required|min_len,2'
));
if ($data ['is_valid'] === true) {
// continue
} else {
$this->index($data ['is_valid']); // show error messages
die();
}
}
}
View:
<div class="alert alert-danger"><?php var_dump($error); ?></div>
... <button type="submit">Save (calls save())</button>
var_dump($error) always shows bool(false).