|
@@ -103,6 +103,43 @@ class Form {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static function renderCountryOptions($selected_value = null) {
|
|
|
|
|
+
|
|
|
|
|
+ $file = ROOT_DIR . "/files/countries.json";
|
|
|
|
|
+ $threshold = time() - (7 * 86400);
|
|
|
|
|
+
|
|
|
|
|
+ if(false && file_exists($file) && filemtime($file) > $threshold) {
|
|
|
|
|
+ $countries_json = @file_get_contents($file);
|
|
|
|
|
+ $countries = json_decode($countries_json);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $url = "http://country.io/names.json";
|
|
|
|
|
+ $countries_json = @file_get_contents($url);
|
|
|
|
|
+ $countries = json_decode($countries_json);
|
|
|
|
|
+
|
|
|
|
|
+ if($countries) {
|
|
|
|
|
+ file_put_contents($file, $countries_json);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!$countries) return false;
|
|
|
|
|
+
|
|
|
|
|
+ $country_pairs = get_object_vars($countries);
|
|
|
|
|
+ sort($country_pairs);
|
|
|
|
|
+ $countries = array_values($country_pairs);
|
|
|
|
|
+
|
|
|
|
|
+ ?>
|
|
|
|
|
+ <option value="">Select Country</option>
|
|
|
|
|
+ <?php
|
|
|
|
|
+
|
|
|
|
|
+ foreach($countries as $country) {
|
|
|
|
|
+ $selected = ($selected_value === $country) ? "selected" : "";
|
|
|
|
|
+ ?>
|
|
|
|
|
+ <option value="<?=htmlspecialchars($country)?>" <?=$selected?>><?=htmlspecialchars($country)?></option>
|
|
|
|
|
+ <?php
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static function renderField($options) {
|
|
public static function renderField($options) {
|
|
|
|
|
|
|
|
switch($options->type) {
|
|
switch($options->type) {
|