Hello.
I'm loosing my head now with something I cannot achieve.
Imagine a view with a simple form.
A controller with 2 methods: one to echo the view. The other to process the form after submission.
Controller (home):
PHP Code:
public function index(){
return view('form');
}
public function submission(){
$result = $this->validate([
'username' => 'required',
'password' => 'required'
]);
if(!$result){
return redirect()->back()->withInput();
} else {
echo 'Submission OK!';
}
}
View (form)
PHP Code:
<?= $this->validator->listErrors() ?>
<?= form_open('home/submission')?>
<div>
<input type="text" name="username" value="<?= old('username') ?>">
</div>
<div>
<input type="text" name="password" value="<?= old('password') ?>">
</div>
<div>
<input type="submit" value="Login">
</div>
</form>
Question: How can I redirect to back, with input data AND with the validation errors so I can display them in the form view?