Skip to content

Instantly share code, notes, and snippets.

@pije76
Forked from dave-mills/example.php
Created June 23, 2019 08:05
Show Gist options
  • Save pije76/ec82352e9d6bbee6c1c299eb8e1667bd to your computer and use it in GitHub Desktop.
Save pije76/ec82352e9d6bbee6c1c299eb8e1667bd to your computer and use it in GitHub Desktop.
Example Callback function for Ultimate Member dropdown field
function getCities() {
//get the value from the 'parent' field, sent via the AJAX post.
$choice = $_POST['parent_option'];
//Depending on the value of $choice, return a different array.
switch($choice) {
case "France":
$cities = [
"Paris" =>"Paris",
"Marseille" => "Marseille",
"Lyon" => "Lyon"
];
break;
case "Spain":
$cities = [
"Madrid"=>"Madrid",
"Barcelona"=>"Barcelona"
];
break;
default:
//code to do something if other options are not selected (throw an error, or set $cities to a default array)
$cities = ["no city"];
}
return $cities;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment