Skip to content

Instantly share code, notes, and snippets.

@goodmuyis
Forked from dave-mills/example.php
Last active January 30, 2019 17:20
Show Gist options
  • Save goodmuyis/3fff70671a20179893969884016b7fa1 to your computer and use it in GitHub Desktop.
Save goodmuyis/3fff70671a20179893969884016b7fa1 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;
}
@goodmuyis
Copy link
Author

//Below for Complete Nigeria States and LGAs

`function getLgas() {
//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 "Abia":$lgas=["AbaNorth","AbaSouth","Arochukwu","Bende","Ikwano","IsialaNgwaNorth","IsialaNgwaSouth","Isuikwuato","Obingwa","Ohafia","Osisioma","Ugwunagbo","UkwaEast","UkwaWest","UmuahiaNorth","UmuahiaSouth","Umuneochi"];break;
case "Adamawa":$lgas=["Demsa","Fufore","Ganaye","Gireri","Gombi","Guyuk","Hong","Jada","Lamurde","Madagali","Maiha","Mayo-Belwa","Michika","MubiNorth","MubiSouth","Numan","Shelleng","Song","Toungo","YolaNorth","YolaSouth"];break;
case "AkwaIbom":$lgas=["Abak","EasternObolo","Eket","EsitEket","EssienUdim","EtimEkpo","Etinan","Ibeno","IbesikpoAsutan","IbionoIbom","Ika","Ikono","IkotAbasi","IkotEkpene","Ini","Itu","Mbo","MkpatEnin","NsitAtai","NsitIbom","NsitUbium","ObotAkara","Okobo","Onna","Oron","OrukAnam","UdungUko","Ukanafun","Uruan","Urue-Offong-Oruko","Uyo"];break;
case "Anambra":$lgas=["Aguata","AnambraEast","AnambraWest","Anaocha","AwkaNorth","AwkaSouth","Ayamelum","Dunukofia","Ekwusigo","IdemiliNorth","Idemilisouth","Ihiala","Njikoka","NnewiNorth","NnewiSouth","Ogbaru","OnitshaNorth","OnitshaSouth","OrumbaNorth","OrumbaSouth","Oyi"];break;
case "Bauchi":$lgas=["Alkaleri","Bauchi","Bogoro","Damban","Darazo","Dass","Ganjuwa","Giade","Itas-Gadau","Jama'are","Katagum","Kirfi","Misau","Ningi","Shira","Tafawa-Balewa","Toro","Warji","Zaki"];break;
case "Bayelsa":$lgas=["Brass","Ekeremor","Kolokuma-Opokuma","Nembe","Ogbia","Sagbama","SouthernJaw","Yenegoa"];break;
case "Benue":$lgas=["Ado","Agatu","Apa","Buruku","Gboko","Guma","GwerEast","GwerWest","Katsina-Ala","Konshisha","Kwande","Logo","Makurdi","Obi","Ogbadibo","Oju","Okpokwu","Ohimini","Oturkpo","Tarka","Ukum","Ushongo","Vandeikya"];break;
case "Bornu":$lgas=["Abadam","Askira-Uba","Bama","Bayo","Biu","Chibok","Damboa","Dikwa","Gubio","Guzamala","Gwoza","Hawul","Jere","Kaga","Kala-Balge","Konduga","Kukawa","KwayaKusar","Mafa","Magumeri","Maiduguri","Marte","Mobbar","Monguno","Ngala","Nganzai","Shani"];break;
case "CrossRiver":$lgas=["Akpabuyo","Odukpani","Akamkpa","Biase","Abi","Ikom","Yarkur","Odubra","Boki","Ogoja","Yala","Obanliku","Obudu","CalabarSouth","Etung","Bekwara","Bakassi","CalabarMunicipality"];break;
case "Delta":$lgas=["Oshimili","Aniocha","AniochaSouth","IkaSouth","IkaNorth-East","NdokwaWest","NdokwaEast","Isokosouth","IsokoNorth","Bomadi","Burutu","UghelliSouth","UghelliNorth","EthiopeWest","EthiopeEast","Sapele","Okpe","WarriNorth","WarriSouth","Uvwie","Udu","WarriCentral","Ukwani","OshimiliNorth","Patani"];break;
case "Ebonyi":$lgas=["AfikpoSouth","AfikpoNorth","Onicha","Ohaozara","Abakaliki","Ishielu","lkwo","Ezza","EzzaSouth","Ohaukwu","Ebonyi","Ivo"];break;
case "Edo":$lgas=["EsanNorth-East","EsanCentral","EsanWest","Egor","Ukpoba","Central","EtsakoCentral","Igueben","Oredo","OviaSouthWest","OviaSouth-East","Orhionwon","Uhunmwonde","EtsakoEast","EsanSouth-East"];break;
case "Ekiti":$lgas=["Ado","Ekiti-East","Ekiti-West","Emure-Ise-Orun","EkitiSouth-West","Ikare","Irepodun","Ijero","Ido-Osi","Oye","Ikole","Moba","Gbonyin","Efon","Ise-Orun","Ilejemeje"];break;
case "Enugu":$lgas=["EnuguSouth","Igbo-EzeSouth","EnuguNorth","Nkanu","UdiAgwu","Oji-River","Ezeagu","IgboEzeNorth","Isi-Uzo","Nsukka","Igbo-Ekiti","Uzo-Uwani","EnuguEast","Aninri","NkanuEast","Udenu"];break;
case "Gombe":$lgas=["Akko","Balanga","Billiri","Dukku","Kaltungo","Kwami","Shomgom","Funakaye","Gombe","Nafada-Bajoga","Yamaltu-Delta"];break;
case "Imo":$lgas=["Aboh-Mbaise","Ahiazu-Mbaise","Ehime-Mbano","Ezinihitte","IdeatoNorth","IdeatoSouth","Ihitte-Uboma","Ikeduru","IsialaMbano","Isu","Mbaitoli","Mbaitoli","Ngor-Okpala","Njaba","Nwangele","Nkwerre","Obowo","Oguta","Ohaji-Egbema","Okigwe","Orlu","Orsu","OruEast","OruWest","Owerri-Municipal","OwerriNorth","OwerriWest"];break;
case "Jigawa":$lgas=["Auyo","Babura","BirniKudu","Biriniwa","Buji","Dutse","Gagarawa","Garki","Gumel","Guri","Gwaram","Gwiwa","Hadejia","Jahun","KafinHausa","KaugamaKazaure","KiriKasamma","Kiyawa","Maigatari","MalamMadori","Miga","Ringim","Roni","Sule-Tankarkar","Taura","Yankwashi"];break;
case "Kaduna":$lgas=["Birni-Gwari","Chikun","Giwa","Igabi","Ikara","jaba","Jema'a","Kachia","KadunaNorth","KadunaSouth","Kagarko","Kajuru","Kaura","Kauru","Kubau","Kudan","Lere","Makarfi","Sabon-Gari","Sanga","Soba","Zango-Kataf","Zaria"];break;
case "Kano":$lgas=["Ajingi","Albasu","Bagwai","Bebeji","Bichi","Bunkure","Dala","Dambatta","DawakinKudu","DawakinTofa","Doguwa","Fagge","Gabasawa","Garko","Garum","Mallam","Gaya","Gezawa","Gwale","Gwarzo","Kabo","KanoMunicipal","Karaye","Kibiya","Kiru","kumbotso","Kunchi","Kura","Madobi","Makoda","Minjibir","Nasarawa","Rano","RiminGado","Rogo","Shanono","Sumaila","Takali","Tarauni","Tofa","Tsanyawa","TudunWada","Ungogo","Warawa","Wudil"];break;
case "Katsina":$lgas=["Bakori","Batagarawa","Batsari","Baure","Bindawa","Charanchi","Dandume","Danja","DanMusa","Daura","Dutsi","Dutsin-Ma","Faskari","Funtua","Ingawa","Jibia","Kafur","Kaita","Kankara","Kankia","Katsina","Kurfi","Kusada","Mai'Adua","Malumfashi","Mani","Mashi","Matazuu","Musawa","Rimi","Sabuwa","Safana","Sandamu","Zango"];break;
case "Kebbi":$lgas=["Aleiro","Arewa-Dandi","Argungu","Augie","Bagudo","BirninKebbi","Bunza","Dandi","Fakai","Gwandu","Jega","Kalgo","Koko-Besse","Maiyama","Ngaski","Sakaba","Shanga","Suru","Wasagu-Danko","Yauri","Zuru"];break;
case "Kogi":$lgas=["Adavi","Ajaokuta","Ankpa","Bassa","Dekina","Ibaji","Idah","Igalamela-Odolu","Ijumu","Kabba-Bunu","Kogi","Lokoja","Mopa-Muro","Ofu","Ogori-Mangongo","Okehi","Okene","Olamabolo","Omala","YagbaEast","YagbaWest"];break;
case "Kwara":$lgas=["Asa","Baruten","Edu","Ekiti","Ifelodun","IlorinEast","IlorinWest","Irepodun","Isin","Kaiama","Moro","Offa","Oke-Ero","Oyun","Pategi"];break;
case "Lagos":$lgas=["Agege","Ajeromi-Ifelodun","Alimosho","Amuwo-Odofin","Apapa","Badagry","Epe","Eti-Osa","Ibeju-Lekki","Ifako-Ijaye","Ikeja","Ikorodu","Kosofe","LagosIsland","LagosMainland","Mushin","Ojo","Oshodi-Isolo","Shomolu","Surulere"];break;
case "Nasarawa":$lgas=["Akwanga","Awe","Doma","Karu","Keana","Keffi","Kokona","Lafia","Nasarawa","Nasarawa-Eggon","Obi","Toto","Wamba"];break;
case "Niger":$lgas=["Agaie","Agwara","Bida","Borgu","Bosso","Chanchaga","Edati","Gbako","Gurara","Katcha","Kontagora","Lapai","Lavun","Magama","Mariga","Mashegu","Mokwa","Muya","Pailoro","Rafi","Rijau","Shiroro","Suleja","Tafa","Wushishi"];break;
case "Ogun":$lgas=["AbeokutaNorth","AbeokutaSouth","Ado-Odo-Ota","EgbadoNorth","EgbadoSouth","Ewekoro","Ifo","IjebuEast","IjebuNorth","IjebuNorthEast","IjebuOde","Ikenne","Imeko-Afon","Ipokia","Obafemi-Owode","OgunWaterside","Odeda","Odogbolu","RemoNorth","Shagamu"];break;
case "Ondo":$lgas=["AkokoNorthEast","AkokoNorthWest","AkokoSouthAkureEast","AkokoSouthWest","AkureNorth","AkureSouth","Ese-Odo","Idanre","Ifedore","Ilaje","Ile-Oluji","Okeigbo","Irele","Odigbo","Okitipupa","OndoEast","OndoWest","Ose","Owo"];break;
case "Osun":$lgas=["Aiyedade","Aiyedire","AtakumosaEast","AtakumosaWest","Boluwaduro","Boripe","EdeNorth","EdeSouth","Egbedore","Ejigbo","IfeCentral","IfeEast","IfeNorth","IfeSouth","Ifedayo","Ifelodun","Ila","IleshaEast","IleshaWest","Irepodun","Irewole","Isokan","Iwo","Obokun","Odo-Otin","Ola-Oluwa","Olorunda","Oriade","Orolu","Osogbo"];break;
case "Oyo":$lgas=["Afijio","Akinyele","Atiba","Atigbo","Egbeda","IbadanCentral","IbadanNorth","IbadanNorthWest","IbadanSouthEast","IbadanSouthWest","IbarapaCentral","IbarapaEast","IbarapaNorth","Ido","Irepo","Iseyin","Itesiwaju","Iwajowa","Kajola","LageluOgbomoshoNorth","OgbmoshoSouth","OgoOluwa","Olorunsogo","Oluyole","Ona-Ara","Orelope","OriIre","OyoEast","OyoWest","SakiEast","SakiWest","Surulere"];break;
case "Plateau":$lgas=["BarikinLadi","Bassa","Bokkos","JosEast","JosNorth","JosSouth","Kanam","Kanke","LangtangNorth","LangtangSouth","Mangu","Mikang","Pankshin","Qua'anPan","Riyom","Shendam","Wase"];break;
case "Rivers":$lgas=["Abua-Odual","AhoadaEast","AhoadaWest","AkukuToru","Andoni","Asari-Toru","Bonny","Degema","Emohua","Eleme","Etche","Gokana","Ikwerre","Khana","Obia-Akpor","Ogba-Egbema-Ndoni","Ogu-Bolo","Okrika","Omumma","Opobo-Nkoro","Oyigbo","Port-Harcourt","Tai"];break;
case "Sokoto":$lgas=["Binji","Bodinga","Dange-shnsi","Gada","Goronyo","Gudu","Gawabawa","Illela","Isa","Kware","kebbe","Rabah","Sabonbirni","Shagari","Silame","SokotoNorth","SokotoSouth","Tambuwal","Tqngaza","Tureta","Wamako","Wurno","Yabo"];break;
case "Taraba":$lgas=["Ardo-kola","Bali","Donga","Gashaka","Cassol","Ibi","Jalingo","Karin-Lamido","Kurmi","Lau","Sardauna","Takum","Ussa","Wukari","Yorro","Zing"];break;
case "Yobe":$lgas=["Bade","Bursari","Damaturu","Fika","Fune","Geidam","Gujba","Gulani","Jakusko","Karasuwa","Karawa","Machina","Nangere","NguruPotiskum","Tarmua","Yunusari","Yusufari"];break;
case "Zamfara":$lgas=["Anka","Bakura","BirninMagaji","Bukkuyum","Bungudu","Gummi","Gusau","Kaura","Namoda","Maradun","Maru","Shinkafi","TalataMafara","Tsafe","Zurmi"];break;
case "Abuja":$lgas=["Gwagwalada","Kuje","Abaji","AbujaMunicipal","Bwari","Kwali"];break;
default:
//code to do something if other options are not selected (throw an error, or set $cities to a default array)
$lgas = ["Error Fetching '".$choice."' LGAs"];

}
return $lgas;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment