Welcome Guest, Not a member yet? Register   Sign In
redirect back withInput requries session otherwise old() empty
#1

I am not sure if this is the correct behaviout.

In one of my controller methods -

PHP Code:
public function test() {
 
       $data_post $this->request->getPost();
 
       if(!empty($data_post)) {
 
           $validation $this->validate(
 
               ['what' => 'required',],
 [
'what' => ['required'=>'Please enter what is required']]);

 if(
$validation == false) {
 
redirect()->back()->withInput();
 exit;
 
           } else {
 
//valid submission
 

 }
 
 
$html '<form method="post">
 <input type="text" class="form-control" name="what" id="what" value="'
.old('what').'" />
 <button class="btn btn-success" type="submit">Submit</button>
 </form>'
;
 
$html .= service('validation')->listErrors();

 echo 
view('myview', ['html' => $html]);
 


It prints out the validation error message but old doesn't fill in the value in the input box.

However, if I just add
PHP Code:
session() 
in this code above it works fine.

Is this how it it is supposed to work? Or perhaps I need to make a session call in the constructor of the controller so that session is available in all the methods?
Reply


Messages In This Thread
redirect back withInput requries session otherwise old() empty - by happyape - 10-11-2018, 12:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB