Larvel 5.2 error validation checks empty at random

I have something very strange with my Laravel app validation. I have an application in which a user can access it only with his / her unique hash / code in the URL. When the URL with the hash matches the user, I pre-populate the form with user profile information. Then the user must confirm / complete / change the information using the form. This works fine, but sometimes when submitting a form, validation does not behave normally.

For example, I leave the fields empty that are necessary, and I submit the form, I am redirected back, my errors are displayed in the form fields with a beautiful red frame. All is good so far. However, for some unknown reason, sometimes when you submit a form with an empty value in the field that is required for verification, it redirects back and displays the completed profile form again, but the error variable is empty, but the verification has not yet been completed

They don’t have a line to draw when this happens, sometimes it happens on the first pitch, sometimes I have to submit the form 30 times before this happens. At the moment, we examined it with an additional level of interface verification, because the application had to live, but I can’t stop thinking about why and how this happens.

I use the class Requestfor validation, but I also tried to create a manual validator in my controller, but this has exactly the same behavior. At first, I thought that this had something to do with pre-filling out the form, so I tried it when there are errors, and I don't fill out anything (except entering the old one, of course), but the problem still exists.

The strangest part of all this is that the errors are empty, but some required fields were not filled (and their names are correct), because the problem does not always occur. I could not reproduce the problem on my local and intermediate env, but it continues to happen on my real server.

, - , . 1000 , - , , , .

: . . , , .

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class RegistrationRequest extends Request
{
    /**
     * 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 [
            'hash'       => 'required|exists:users,hash',
            'language'   => 'required|in:NLD,FRA',
            'title'      => 'required',
            'firstName'  => 'required',
            'lastName'   => 'required',
            'street'     => 'required',
            'postalCode' => 'required',
            'city'       => 'required',
            'email'      => 'required|email',
            'birthday'   => 'required|date_format:d/m/Y',
            'tac'        => 'required'
        ];
    }
}

.

public function index($hash)
{
   $user = $this->user->byHash($hash);

   if(is_null($user)) {
      return redirect()->to('/');
   }

   if(! is_null($user->myRelationName)) {
      return redirect()->route('thanks');
   }

   return view('my-view', ['user' => $user]);
}

public function store(RegistrationRequest $request)
{
    $user             = $this->user->byHash($request->hash);
    $user->language   = $request->language;
    $user->title      = $request->title;
    $user->firstName  = $request->firstName;
    $user->lastName   = $request->lastName;
    $user->street     = $request->street;
    $user->postalCode = $request->postalCode;
    $user->city       = $request->city;
    $user->email      = $request->email;
    $user->birthday   = $request->birthday;
    $user->tac        = true;
    $user->ip         = $this->getRemoteIPAddress();
    $user->save();

    return redirect()->route('my-route', ['hash' => $request->hash]);
}

Vieuw.blade.php

@extends('layouts.master')

@section('content')


<div class="bottom">
    <div class="form-container">

        <h2>{{trans('merci.register_maintitle')}}</h2>
        <p>{!!trans('merci.register_p1')!!}</p>

        <p>{!!trans('merci.register_p2')!!}</p>

        <h3>{!!trans('merci.register_h3')!!}</h3>

        {{ Form::open(['route' => 'register.store', 'class' => 'form', 'id' => "register-form"]) }}
            {{Form::hidden('hash', $user->hash, array("id" => "hash"))}}

            <div class="form-field-wrap form-group language {{$errors->has('language')  ? 'has-error' : null}}">
                {{ Form::label('language', trans('merci.register_language'), array('class' => 'form-field-text-label radio-label'))}}

                {{ Form::radio('language', trans('merci.register_language1_value'), ($user->language == trans('merci.register_language1_value')) ? true : false, array('id' => 'nl-rad')) }}
                <span>{{trans('merci.register_language1_label')}}</span>

                {{ Form::radio('language', trans('merci.register_language2_value') , ($user->language == trans('merci.register_language2_value')) ? true : false, array('class' => 'radio', "id"=> 'fr-rad')) }} 
                <span>{{trans('merci.register_language2_label')}}</span>
            </div>

            <div class="form-field-wrap form-group title {{$errors->has('title')  ? 'has-error' : null}}">

                {{ Form::label('title', trans('merci.register_title'), array('class' => 'form-field-text-label radio-label'))}}

                {{ Form::radio('title', trans('merci.register_title1_value'), ($user->title == trans('merci.register_title1_value')) ? true : false) }} 
                <span>{{trans('merci.register_title1_label')}}</span>

                {{ Form::radio('title', trans('merci.register_title2_value'), ($user->title == trans('merci.register_title2_value')) ? true : false, array('class' => 'radio')) }} 
                <span>{{trans('merci.register_title2_label')}}</span>
            </div>

            <div class="form-field-wrap form-group lastName {{$errors->has('lastName')  ? 'has-error' : null}}">
                {{ Form::label('lastName', trans('merci.register_lastName'), array('id' => 'lastName', 'class' => 'form-field-text-label'))}}

                {{ Form::text('lastName', $user->lastName, array('class' => 'form-field-text-input')) }}
            </div>

            <div class="form-field-wrap form-group firstName {{$errors->has('firstName')  ? 'has-error' : null}}">
                {{ Form::label('firstName', trans('merci.register_firstName') , array('class' => 'form-field-text-label'))}}

                {{ Form::text('firstName', $user->firstName, array('class' => 'form-field-text-input')) }}
            </div>

            <div class="extramargin form-field-wrap form-group street {{$errors->has('street')  ? 'has-error' : null}}">
                {{ Form::label('street', trans('merci.register_street'), array('class' => 'form-field-text-label'))}}

                {{ Form::text('street', $user->street, array('class' => 'form-field-text-input big')) }}
            </div>

            <div class="smallerpostal form-field-wrap form-group postalCode {{$errors->has('postalCode')  ? 'has-error' : null}}">
                {{ Form::label('postalCode', trans('merci.register_postalCode'), array('class' => 'form-field-text-label smaller-label'))}}

                {{ Form::text('postalCode', $user->postalCode, array('class' => 'form-field-text-input smaller')) }}
            </div>

            <div class="smallercity form-field-wrap form-group city {{$errors->has('city')  ? 'has-error' : null}}">

                {{ Form::label('city', trans('merci.register_city'), array('class' => 'form-field-text-label smal-label'))}}

                {{ Form::text('city', $user->city, array('class' => 'form-field-text-input smal')) }}
            </div>

            <div class="extramargin form-field-wrap form-group email {{$errors->has('email')  ? 'has-error' : null}}">
                {{ Form::label('email', trans('merci.register_email'), array('class' => 'form-field-text-label'))}}

                {{ Form::email('email', $user->email, array('class' => 'form-field-text-input ')) }}
            </div>

            <div class="form-field-wrap form-group birthday {{$errors->has('birthday')  ? 'has-error' : null }} ">
                {{ Form::label('birthday', trans('merci.register_birthday'), array('class' => 'form-field-text-label', "id" => "birthdate"))}}

                {{ Form::text('birthday', $user->birthday, array('class' => 'form-field-text-input', "id"=>"datepicker")) }}
            </div>

            <div class="check form-field-wrap form-group  tac {{$errors->has('tac')  ? 'has-error' : null }}">
                {{ Form::checkbox('tac', trans('merci.register_tac_value'), false, array('class' => 'form-field-checkbox', "id" => "tac"))}} 
                {{ Form::label('tac', trans('merci.register_tac_label'), array('class' => 'form-field-error-label')) }}
                <span>{!!trans('merci.register_tac_label_link')!!}</span>
            </div>

            @if (count($errors) > 0)
            <div id="error server" style='display:none;'>
            @else
            <div id="error" style='display:none;'>
            @endif
                <p class="error">{{trans('merci.register_error')}}</p>
            </div>


            {!! Form::submit(trans('merci.register_submit'), array('class' => 'btn-main btn')) !!}
        {{ Form::close() }}
        <small>{{trans('merci.register_mandatory')}}</small>

    </div>
</div>
<script src="{{ asset('js/validate.js') }}"></script>
@stop
+4
1

, , $errors, .

, , CSRF (. ).

$errors , . (. ).

// Make sure any routes that need access to session features are placed within

Route::group(['middleware' => 'web'], function () {

    Route::get('/', 'MyController@index');
});

, blade- .

{{ old('username') }} 
-1

All Articles