Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

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);
Last updated 9 years ago.
0
Solution

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
Last updated 9 years ago.
0

@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:

  • POST from the form with ajax to /some/route
  • Method on /some/route does the validation, and attempts to save the record. It will return a JSON response of either success, or an array of validation errors
  • In the .success() or .error() methods of your ajax query, parse that JSON response and output things on the page.
Last updated 9 years ago.
0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.