Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation problem with "*.name" after update from Laravel 5.2.30 to next versions #14232

Closed
migoca opened this issue Jul 6, 2016 · 5 comments

Comments

@migoca
Copy link

migoca commented Jul 6, 2016

After upgrading Laravel from 5.2.30 to .31 and next versions I have problem with these types of validations:

  public function rules()
    {
        return [
            '*.name' => 'required',
            '*.slug' => 'required|alpha_dash'
        ];
    }

I use this to validate for multiple languages: es.name, en.name, it.name, etc. But with the update the result is:

The _token.name field is required.
The _token.slug is required.

In my form i have:

{!! csrf_field() !!}
### And the inputs:
<input type="text" name="es[name]">
<input type="text" name="en[name]">
<input type="text" name="es[slug]">
<input type="text" name="en[slug]">
@taylorotwell
Copy link
Member

@themsaid any ideas?

@themsaid
Copy link
Member

themsaid commented Jul 6, 2016

@migoca your validation rules here state that for every form field there should be array members with keys name and slug, this includes the csrf token field _token.

I don't think this behaviour is recent, are you sure it was working differently in 5.2.30?

Anyways I suggest you use a structure like this:

<input type="text" name="post_data[es][name]">
<input type="text" name="post_data[es][slug]">
return [
    'post_data.*.name' => 'required',
    'post_data.*.slug' => 'required|alpha_dash'
];

@migoca
Copy link
Author

migoca commented Jul 7, 2016

Yes @themsaid in 5.2.30 these validation rules works like I expected, but when i update to 5.2.31 ..5.2.39 and fill these fields the form don't pass the validation rules and return with:
The _token.name field is required.
The _token.slug is required.

Maybe was for this pull request #13224 merged in 5.2.31, fixing data_set issue.

I like the structure that you have suggested, I will try! Thanks

@themsaid
Copy link
Member

themsaid commented Jul 9, 2016

@migoca I'm not sure if that PR caused the change in behaviour, but anyways I think the current behaviour makes sense, when you use * at the beginning of the attribute it means any field and in this case it includes the csrf token field as well.

@migoca
Copy link
Author

migoca commented Jul 11, 2016

Thanks @themsaid for your help! You are right, the current behavior makes more sense.

@migoca migoca closed this as completed Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants