0

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).

1 Answer 1

2

Basically you wasn't sent error to render, as i see.

public function index($error)
{
    $data ['title'] = $this->language->get('welcome_text');
    $data ['error'] = $error;

    View::renderTemplate('header', $data);
    View::render('insert/form', $data);
    View::renderTemplate('footer', $data);
}

View

<div class="alert alert-danger"><?php var_dump($data['error']); ?></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.