I am trying to do pretty much the same thing (update PHP variables without reloading) and I’ve tried my best to follow this thread but it’s so specific to the OPs example that I can’t make much sense of it.
Simply put, I would like to update the data passed to my form from my controller when one of the input fields is changed. I’ve cheaply mocked this up with some JS that submits the form when it detects an input change, however I’d like to update the form without a page reload.
I’ve dabbled with AJAX before (Load More with AJAX) however this almost seems simpler if I can do it via a route and a JS file.
My controller is getting the values from URL parameters:
//get Used Filters
$query = get('q');
$topPlace = get('topPlace');
$type = get('type');
$ucategories = get('categories');
$utags = get('tags');
//Apply Used Filters
$aplaces = $page->children()->listed()->flip()
->when($query, function ($query) {
return $this->search($query, 'title|category|tags|locations');
})
->when($topPlace, function ($topPlace) {
return $this->filterBy('topPlace', true);
})
->when($type, function ($type) {
if($type != 'all'){
$return = $this->filterBy('type', $type);
} else {
$return = $this;
}
return $return;
})
->when($ucategories, function ($ucategories) {
return $this->filterBy('category', 'in', $ucategories, ',');
})
->when($utags, function ($utags) {
return $this->filterBy('tags', 'in', $utags, ',');
});
My template is disabling certain fields based on what has been selected, which is why it would be nice for this to happen on input change. What’s the best way to approach this?
I guess another question is how do I achieve this when using URL parameters for the search?