0

I am wondering if anyone knows how I can do this.

Currently, I am using form request validation so my store method looks something like

public function store(ProfileStore $request)
{
// do stuff. 
   Input::flush(); 
   return redirect()->back();
} 

^ Note the input flush, I don't want certain input stored as "old input" or passed back to the form so I am flushing it.

and then in my ProfileStore I have a some basic validation (eg.

public function rules()
{
    return [
        'title' => 'required|max:255',
        'body' => 'required',
    ];
}

The problem is when I use Request Validation, its passing the the input back into the form along with the error messages. I have tried flushing input from the validation file, but doesn't work.

If I manually create a validator from my store method and not use Request Validation it works fine and will not pass back input.

Update:

So I am using Laravel Collective Forms & HTML, I think its related to that. Which is weird because I am using Form::open and as far as I know only Form model binding should be doing this on Form::model..

If I remove

Form::text('testfield', null);

and replace with standard input

<input tpye="text" name="testfield" value="">

No input is returned after validation which is correct. However when using Form::input values are returned from validation.

      {!! Form::open(['route' => ['frontend.account.profile.save'], 'id' => 'profile-update', 'class' => 'profile', 'role' => 'form']) !!}
        <div class="form-body">
            <div class="row" id="billing_details_div">
                <div class="col-xs-12">

                    {{-- Input gets passed back after failed validation when using Form::text() --}}

                     Form::text('testfield', null);

{{-- No Input gets passed back when using stantard HTML input
    <input tpye="text" name="testfield" value=""> --}} 

               </div>
                <div class="col-md-12 text-center">
                    <button type="submit" class="btn btn-lg btn-success"><span class="glyphicon glyphicon-floppy-disk"></span> Update Profile</button>
                </div>
            </div>
        </div>
        {!! Form::close() !!}

Any ideas?

3
  • You mean old inputs shows up in the form after redirect back ? Please include your form html code in your question Commented Oct 21, 2015 at 6:41
  • Correct, It seems to be related to Form:: because standard html input returns no input. Commented Oct 21, 2015 at 7:06
  • using only Form::text('testfield') without even ` Input::flush(); ` suppose to work out of box, Have you tested in anther web browser? Commented Oct 21, 2015 at 7:55

1 Answer 1

2

Write this function in your ProfileStore request class and it should fix that.

public function response(array $errors)
{
    if ($this->ajax() || $this->wantsJson()) {
        return new JsonResponse($errors, 422);
    }

    return $this->redirector->to($this->getRedirectUrl())
                                 ->withErrors($errors, $this->errorBag);
}

I'm not quite sure if it works, so let me know if it does. ;)

Update

Try this as well

protected $dontFlash = ['password', 'password_confirmation', 'your-other-inputs'];
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, thank you. Both of these work. I will use. protected $dontFlash =['field']
Glad I could help you. Please check the check mark blow the answer rank if the question is solved. (y)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.