ever tried as form action:
$_SERVER['PHP_SELF']
// or
$_SERVER['SCRIPT_NAME']
// or
$_SERVER['REQUEST_URI']
?
if you want to check the various outputs use
dd($_SERVER);
I have done a get route to display the page. I then did route a post to post form data.
Then I passed the $data variable to blade where I did an isset to check if it is created which displays the results
Display initial page
public function destinationSearchGet(){
$headData = array('pageTitle' => 'Admin Home - View all destinations');
return view('admin.destination_search', $headData);
}
post data back to the same page and create a new variable
public function destinationSearchPost(){
$headData = array('pageTitle' => 'Admin Home - Search results');
$formData = Request::input('destination');
$data = ParentRegionList::destinationSearch($formData);
return view('admin.destination_search', $headData)->with(compact('data'))
}
use blade to check if it exists
@if (isset($data))
<p>{{dd($data)}}</p>
@endif
@ottz0's suggestion is what I do as well. You can also create two separate routes (one GET route to display the form initially, one POST route to handle the form) and still display the same view at the end of it (or redirect elsewhere if the save was successful).
That said, you mentioned using ajax -- if you want to try to figure that out as a solution, it works a lot smoother than asking for a new server-rendered template. You'd basically do:
Thanks dyyylan
Can you post the Ajax method on here (just the actual call will do). I'll use it next time. I have it working pretty good and fast now.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community