Radio button in my laravel 5.4 cannot be read by request -


all of other request in view included in request using dd($request), radio button input cannot read request. attached here code

view

<form method="post" action="{{route('update-dependent')}}">    <div class="form-group">        {{csrf_field()}}    <div class="form-group">     <label>last name</label>     <input type="text" name="lname" value="{{$dependent->lname}}" class="form-control">     </div>                                                        <div class="form-group">         {{-- conditional statement check geneder --}}         <input type="hidden" name="gender" value="bading" class="form-control">         <label>male</label>              <input type="radio" name="gender" value="male" class="form-control">         <label>female</label>         <input type="radio" name="gender" value="female" class="form-control">         </div>                <div class="form-group">         <label>relationship</label>         <input type="text" name="relationship" value="{{$dependent->relationship}}" class="form-control">         </div>            <div class="form-group">         <button type="submit" class="btn btn-primary">update</button>         </div>  </form> 

controller

   hmo::updatedependent($request);      return redirect()->route('edit', request('hmo_id')); 

model

public static function updatedependent($request) {     db::table('hmos_detail')     ->where('id', $request->get('dependent_id'))     ->update([  'lname'         => $request->get('lname'),                 'gender'        => $request->get('gender'),                 'relationship'  => $request->get('relationship'),     return true; } 

result

 array:2 [▼       "_token" => "sp9fvebl3pi5yaf2jlsfdatntotsz2rheb4bh9ti"       "lname" => "test"       "relationship" => "wife"     ] 

first of if want value of radio make sure have proper validation in place.

if don't know how validate have @ following link https://laravel.com/docs/5.5/validation#validation-quickstart

furthermore if want default value radio button make sure have hidden field have default value case dont need validation.

so basic example

<input type="hidden" name="gender" value="bading" class="form-control"> 

the radio btn have bading default weather selected or not. if add

<input type="radio" name="gender" value="male" class="form-control"> <input type="radio" name="gender" value="female" class="form-control"> 

then hidden field replaced selected value.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -