RPeraltaJr
2/3/2020 - 7:26 PM

Using Optgroup for City, State (Static)

<select name="location" id="location_<?php echo $form_counter; ?>" required>
    <option value="" selected readonly>Select a Location *</option>

    <?php 
        ksort($locations); // reorder locations in alphabetical order
        foreach($locations as $state => $cities): 
        asort($cities);  // reorder cities in alphabetical order
    ?>
        <optgroup label="<?php echo $state; ?>">
            <?php foreach($cities as $city): ?>
                <option value="<?php echo "{$city}, " . convertState($state); ?>"><?php echo "{$city}, " . convertState($state); ?></option>
            <?php endforeach; ?>
        </optgroup>
    <?php endforeach; ?>

</select>
<?php 

$locations = [
    "California" => [
        "Roseville",
        "Sacramento",
        "San Jose",
    ],
    "Florida"   => [
        "Fort Myers",
        "Bonita Springs/Napal",
        "Miami",
        "Palm Beach Gardens",
        "Sunrise/Ft. Lauderdale",
    ],
    "Illinois"  => [
        "Chicago",
        "Deerfield"
    ],
    "Michigan"  => [
        "Grand Rapids",
        "Holland",
        "Kalamazoo",
        "Okemos"
    ],
    "North Carolina" => [
        "Asheville",
        "Charlotte",
        "Winston-Salem"
    ],
    "South Carolina" => [
        "Columbia"
    ],
    "New Hampshire" => [
        "Manchester",
        "Nashua",
        "Portsmouth",
        "Winford",
    ],
    "New York"  => [
        "Manhattan",
        "Medford",
        "Melville",
    ],
    "Texas" => [
        "Cedar Hill",
        "Corsicana",
        "Ennis",
        "Mansfield",
        "Midlothian",
        "Waxahachie",
    ]
];