0
I have a problem, I can not show the error in the validation of forms in the View (MVC done by me) correctly, it is showing in wrong place, I would like it to be on top of the button or the bottom.
Model:
<?php
class Login_Model extends Model {
public $_errorVal;
public function __construct() {
parent::__construct();
}
public function login() {
if (isset($_POST['btn-login'])) {
try {
$form = new Form();
$form->post('username')
->val('required')
->post('password')
->val('required');
$this->_errorVal = $form->submit();
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
}
Controller
<?php
class Login extends Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->view->title = 'Nome da Web - login';
$this->model->login();
$this->view->formValidation = $this->model->_errorVal;
$this->view->render('header');
$this->view->render('login/index');
$this->view->render('footer');
}
}
View:
<section class="section">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-body">
<form method="post">
<div class="form-group">
<input type="text" name="username" placeholder="Usuário" class="form-control">
</div>
<div class="form-group">
<input type="text" name="password" placeholder="Senha" class="form-control">
</div>
<div class="text-right">
<button type="submit" name="btn-login" class="btn btn-success">Entrar</button>
</div>
</form>
<?php
if (isset($this->formValidation)) {
echo $this->formValidation;
}
?>
</div>
</div>
</div>
</div>
</div>
</section>
Screenshot of how you are printing on screen:
I want the message to be displayed below the enter button or on top of it. Note: I don’t want to make use of Frameworks so if anyone suggests I’ll just ignore right?
The project code is on Github: Project here
Are you sure the variable
$this->view->formValidation
is sitting the value?– Guilherme Nascimento
So there is no other logic to do this, at least I did not find... when debugging using
var_dump();
returns me null and I don’t know how to proceed :/, of all cases I put a project link on github pro staff try to help me.– Guilherme SpinXO
Your architecture is a little confusing, but I think I’ve been able to answer.
– Guilherme Nascimento