Skip to content
Advertisement

Value Old() On Laravel Blade, Seems Not To Be Working

I want to retrieve the old value input that user has entered on form, so he/she won’t need to re-enter all the form inputs again.

In order to do that, I have added these:

<input type="text" class="form-control" name="uid" value="{{ (!empty($member)) ? $member->mbr_national_code : old('uid') }}">
<input type="text" class="form-control" name="mobile" value="{{ (!empty($member)) ? $member->mbr_mobile : old('mobile') }}">
<input type="text" class="form-control" name="phone" value="{{ (!empty($member)) ? $member->mbr_phone : old('phone') }}">
<input type="text" class="form-control" name="post_code" value="{{ (!empty($member)) ? $member->mbr_post_code : old('post_code') }}">
<input type="text" class="form-control" name="email" value="{{ (!empty($member)) ? $member->user->usr_email : old('email') }}">
<textarea id="" class="form-control" cols="30" rows="3" name="address" placeholder="Street, block, etc">{{ (!empty($member)) ? $member->mbr_address : old('address') }}</textarea>

So I tried retrieving old requests by saying:

old('input_name') 

But it does not seem to be working, and when the form refreshes, no data added from the last request.

So how to fix this? I would really appreciate any idea or suggestion from you guys…

Thanks.

Advertisement

Answer

Try passing second param to old method

<input type="text" class="form-control" name="uid" value="{{old('uid',$member->mbr_national_code??null)  }}">

Full code

    <input type="text" class="form-control" name="uid" value="{{old('uid',$member->mbr_national_code??null)  }}">
    <input type="text" class="form-control" name="mobile" value="{{  old('mobile',$member->mbr_mobile??null) }}">
    <input type="text" class="form-control" name="phone" value="{{  old('phone',$member->mbr_phone??null) }}">
    <input type="text" class="form-control" name="post_code" value="{{ old('post_code',$member->mbr_post_code??null) }}">
    <input type="text" class="form-control" name="email" value="{{old('email',$member->user->usr_email??null) }}">
    <textarea id="" class="form-control" cols="30" rows="3" name="address" placeholder="Street, block, etc">{{ old('address',$member->mbr_address??null) }}</textarea>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement