I have a problem, I can not show the form validation error in View (MVC done by me) correctly, it is showing in the wrong place, I would like it to stay on top of the button or down.
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>
Image of how you are printing on the screen:
Iwantthemessagetoappearbelowtheenterbuttonorontopofit.Note:IdonotwanttomakeuseofFrameworkssoifsomeonesuggestsI'lljustignoreitright?
TheprojectcodeisinGitHub: Project here