Thanks Bob.
There are a few hundred countries and each country has a large number of zones so loading everything all at once and then changing with javascript isn't ideal (I know that's not what you're suggesting). I'm loading the countries with a snippet on page load already and I've coded up a script to detect the onchange event which will then fire an AJAX call to the page. A plugin is then retrieving the call and running formit with a hook.
Everything seems fine and I can call back a custom response on to the page, but I'm a little unsure how to then grab the data from the hook and return it.
Plugin:
if ($ajax && $post['type'] == 'ajax') {
$return = ['success' => false, 'message' => ''];
$action = $post['action'];
unset($post['type'], $post['action']);
switch ($action) {
// Update Regions/Zones
case "ocGetRegions":
$modx->runSnippet('FormIt',array(
'hooks' => 'ocGetRegions'
));
$return = 'This is my custom response.';
break;
...
}
jQuery:
// Update Regions/Zones
ocGetRegions: function (elem) {
$.post(window.location.href, {
type: 'ajax',
action: 'ocGetRegions',
}).done(function (response) {
$('.my-test-box').html(response);
});
},
Any steer appreciated as always!
[ed. note: lkfranklin last edited this post 5 years, 8 months ago.]