.php
:
session_start()
$_SESSION['nameFocus'] = false;
$_SESSION['emailFocus'] = false;
$_SESSION['passwordFocus'] = false;
$validate = new FormValidator();
$validation = $validate->check();
if($validation->error('name')) $_SESSION['nameFocus'] = true;
else if($validation->error('email')) $_SESSION['emailFocus'] = true;
else if($validation->error('password')) $_SESSION['passwordFocus'] = true;
header('Location : ./my_form.php');
.html
:
<?php session_start() ?>
<form method="post" action="">
<div>
<label>Name</label>
<input type="text" name="name" autofocus="<?php echo $_SESSION['nameFocus'] ? 'on' : 'off' ?>">
</div>
<div>
<label>Email</label>
<input type="text" name="email" autofocus="<?php echo $_SESSION['emailFocus'] ? 'on' : 'off' ?>">
</div>
<div>
<label>Password</label>
<input type="text" name="password" autofocus="<?php echo $_SESSION['passwordFocus'] ? 'on' : 'off' ?>">
</div>
<button>Submit</button>
</form>