php - How do I pass a variable into another page/view? -


i have following scenario. user selects 2 date periods selects contacts database time period.

then on next page, want display contacts passed , have text area field user can type message.

the problem time next page loads $contacts variable empty. how pass variables across 2 pages?

below code select time period

<form method="post" action="selectcontacts">     {{ csrf_field() }}     <div class="row">         <div class="col-lg-3 col-sm-3 col-xs-6">             <div class="form-group{{ $errors->has('date') ? ' has-error' : '' }}">                 <label for="event date">start date</label>                 <input type ='hidden' name='email' value='{{$email}}'>                 <input type ='hidden' name='ip' value='{{$ip}}'>                 <input name="start" type="text" class="form-control" id='fromperiod'  placeholder="date" required                  @if ($errors->has('date'))                     <span class="help-block">                         <strong>{{ $errors->first('date') }}</strong>                     </span>                 @endif             </div>           </div>     </div>     <div class="row">         <div class="col-lg-3 col-sm-3 col-xs-6">             <div class="form-group{{ $errors->has('date') ? ' has-error' : '' }}">                 <label for="event date">end date</label>                 <input name="stop" type="text" class="form-control" id='toperiod'  placeholder="date" required                  @if ($errors->has('date'))                     <span class="help-block">                         <strong>{{ $errors->first('date') }}</strong>                     </span>                 @endif             </div>           </div>     </div>     <div class="row">         <div class="col-lg-12 col-sm-12 col-xs-12">             <input type="submit" class="btn btn-primary pull-right" value="select">             <a href="sendsms" class="btn btn-default pull-left">                 <i class="fa fa-arrow-left" aria-hidden="true"></i>             </a>         </div>     </div> </form> 

then controller handles selectcontacts route.

public function selectcontacts(request $request) {     $startdate=$request->start;     $stopdate=$request->stop;     validator = validator::make($request->all(), [         'start' => 'required|min:10',         'stop' => 'required|min:10'     ]);      if ($validator->fails()) {         return redirect('/sendsms')                ->witherrors($validator)                ->withinput();     }     $sdate=date_create("$startdate");     $start = date_format($sdate,"y/m/d h:i:s");      $date=date_create("$stopdate");     $stop = date_format($date,"y/m/d h:i:s");      $contacts = db::table('payment')                     ->wherebetween('time_paid', [$start, $stop])                     ->paginate(5);       //next page      return view('bulksms.send', 'contacts'=>$contacts]); } 

then lastly view handles text area nad display of contacts:

<form class="form-horizontal" role="form" method="post" action="/fun/sendbulk">      {{ csrf_field() }}     <div class="form-group">         <label for="message" class="col-sm-1 control-label">message</label>         <div class="col-sm-6">             <textarea class="form-control" rows="4" name="message" required="please type message here" placeholder="message"></textarea>         </div>         <input type ='hidden' name='email' value='{{$email}}'>         <input type ='hidden' name='ip' value='{{$ip}}'>     </div>     <div class="form-group">         <div class="col-sm-6 col-sm-offset-1">             <input id="submit" name="submit" type="submit" value="send" class="btn btn-primary pull-right">             <a href="sendsms" class="btn btn-default pull-left">                 <i class="fa fa-arrow-left" aria-hidden="true"></i> cancel             </a>         </div>     </div>   </form>  <div class="row">     <div class="col-sm-4 col-sm-offset-2">         <table class="table table-hover">             <thead>                                     <th>id</th><th>name</th> <th>mobile number</th> <th>remove</th>             </thead>             <tbody>                 @foreach($contacts $contact)                     <tr>                         <td> {{$contact->id }} </td>                         <td> {{$contact->name}}</td>                         <td> {{$contact->msisdn}}</td>                         <td>                             <form action= '' method='post'>                                 {{csrf_field()}}                                 <input type="radio" name="remove" value="other"> <!-- <input type='submit' name='submit' value='submit'> -->                             </form>                         </td>                     </tr>                 @endforeach             </tbody>         </table>         <div class="pull-right">{{ $contacts->links() }}</div>     </div> </div> 

lastly, controller handles /fun/sendbulk route.

public function sendsms(request $request){   $message=$request->message;   $validator = validator::make($request->all(), [       'message' => 'required|max:160',]);   if ($validator->fails()) {       return redirect('/selectcontacts')              ->witherrors($validator)           ->withinput();}     $mob_numbers = implode(", " , $contacts);    $servicearguments = array(         "mobilenumber" => $mobilenum,         "message" => $message         );   $client = new soapclient("http://#smsws?wsdl");    $result = $client->process($servicearguments)     } 

kindly advice

in smssend function add top.

$start=$request->start; $stop=$request->stop;  $contacts = db::table('payment')   ->wherebetween('time_paid', [$start, $stop])   ->paginate(5);  

edit: saw need more stuff: in select contacts route:

return view('bulksms.send',      'contacts'=>$contacts,      'start' => $start,      'stop' => $stop ); 

and in contact view:

<input type ='hidden' name='start' value='{{$start}}'> <input type ='hidden' name='stop' value='{{$stop}}'> 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -