Waavi / Sanitizer

Data sanitizer and form request input sanitation for Laravel 5.
MIT License
428 stars 88 forks source link

Usage in FormRequest #37

Open movepixels opened 5 years ago

movepixels commented 5 years ago

I can not get the filter to work in the FormRequest. I must be missing something.

Added

use Waavi\Sanitizer\Laravel\SanitizesInput;

and

use SanitizesInput; 

And simple function

public function filters() {
    return [
      'name'  => 'trim|strip_tags|escape|uppercase',
      'headline'  => 'trim|strip_tags|escape|uppercase',
    ];
  }

Any input in the form for these fields remains untouched.

Must be something missing.

RatanaKH commented 5 years ago

How about your input ? Can you show?

movepixels commented 5 years ago

The request that gets sent is an simply array.

What specific code would you like to see?

I am using this as a guide.

https://medium.com/@kamerk22/the-smart-way-to-handle-request-validation-in-laravel-5e8886279271

And it mentions Laravel 5.6 I am using v 5.7

Hope that helps, or let me know specificaly code you want to see?

Thanks, Dave

RatanaKH commented 5 years ago

Oh, i see. It's not show error alright ?

Make sure your function authorize() return true. If still not work you should follow this instruction

https://github.com/Waavi/Sanitizer#install

It's easy to configuration. please try your best. Thanks

movepixels commented 5 years ago

Yes its set:

public function authorize()
  {
    return true;
  }

Is there anything other inside the formRequest other than the filters?

xippios commented 5 years ago

Same issue here. Using Laravel 5.8

Edit: It is working fine, had to make an adjustment as I was working with arrays.

movepixels commented 5 years ago

Would you care to share your setup as I still have no luck.

francoism90 commented 4 years ago

@movepixels I do have the same issue, however without using $request->get('input') it works, see #50

<?php

use Illuminate\Foundation\Http\FormRequest;
use Waavi\Sanitizer\Laravel\SanitizesInput;

class UpdateRequest extends FormRequest
{
    use SanitizesInput;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'string|min:1|max:255',
        ];
    }

    /**
     *  Filters to be applied to the input.
     *
     *  @return array
     */
    public function filters()
    {
        return [
            'name'  => 'trim|escape',
        ];
    }
}

See https://laravel.com/docs/6.x/requests#retrieving-input

dd($request->name)); // escaped input (OK)
dd($request->input('name')); // escaped input (OK)
dd($request->get('name')); // unescaped input (not OK)