kinotwins Posted October 2, 2012 Share Posted October 2, 2012 Hi All. Trying to launch my own realtor web page. I'm new with PHP so plz forgive my ignorance. I created a form New Home criteria. $Bedrooms = $_POST['num_beds']; $Bathrooms = $_POST['num_baths']; $BuildingType = $_POST['bldg_type_id']; $MinimumPrice = $_POST['min_price']; $MaximumPrice = $_POST['max_price']; etc... Where I'm stuck is on the Neighborhoods. My form has a field that says "Choose your desired Neighborhood." When a particular city is selected - Scottsdale, for example the onclick="showBlock('area_Scottsdale', this.checked) displays specific Neighborhoods of the respective city. I'd like people to be able to select Neighborhoods from any/all of the 4 (for now) cities - Scottsdale, FH, PV, PHX On the form each city/neighborhood is listed as such: Scottsdale: <input type="checkbox" name="Scottsdale" value="SC" onclick="showBlock('area_Scottsdale', this.checked)"> <input id="ScChkbox0" name="Scottsdale[]" type="checkbox" value="Scottsdale 1"><label for="ScChkbox0"> Scottsdale 1</label> <input id="ScChkbox1" name="Scottsdale[]" type="checkbox" value="Scottsdale 2"><label for="ScChkbox1"> Scottsdale 2</label> ..... <input id="ScChkbox9" name="Scottsdale[]" type="checkbox" value="Scottsdale 10"><label for="ScChkbox9"> Scottsdale 10</label> FH <input type="checkbox" name="Fountain" value="FH" onclick="showBlock('area_Fountain', this.checked)"> <input id="FHChkbox0" name="Fountain[]" type="checkbox" value="FH 1"><label for="FHChkbox0"> FH 1</label> <input id="FHChkbox1" name="Fountain[]" type="checkbox" value="FH 2"><label for="FHChkbox1"> FH 2</label> ...... <input id="FHChkbox9" name="Fountain[]" type="checkbox" value="FH 10"><label for="FHChkbox9"> FH 10</label> etc.... I don't have anything for the Neighborhhods on the PHP side yet. After doing some research, I think I need to implode but I don't know how to script it. Any help is appreciated. Thx Quote Link to comment https://forums.phpfreaks.com/topic/269011-sending-multiple-checkbox-arrays-to-email/ Share on other sites More sharing options...
requinix Posted October 3, 2012 Share Posted October 3, 2012 (edited) Besides actually needing to, you should change the checkbox names to something easier to deal with. Like <input type="checkbox" name="neighborhoods[scottsdale][top] value="SC" onclick="showBlock('area_Scottsdale', this.checked)"> <input id="ScChkbox0" name="neighborhoods[scottsdale][]" type="checkbox" value="Scottsdale 1"><label for="ScChkbox0"> Scottsdale 1</label> <input id="ScChkbox1" name="neighborhoods[scottsdale][]" type="checkbox" value="Scottsdale 2"><label for="ScChkbox1"> Scottsdale 2</label> ..... <input id="ScChkbox9" name="neighborhoods[scottsdale][]" type="checkbox" value="Scottsdale 10"><label for="ScChkbox9"> Scottsdale 10</label> Now $_POST["neighborhoods"] will look like array( "Scottsdale" => array( "top" => "SC", // checked Scottsdale 0 => "Scottsdale 1", // checked #1 1 => "Scottsdale 10" // checked #10 ) ) You can look at just the [number] items to see the neighborhoods but if they didn't check any then all you'll have is the [top]. You can do whatever you'd like with that. [edit] For instance, foreach ($_POST["neighborhoods"] as $place => $options) { // they checked $place if (count($options) == 1 && key($options) == "top") { // they didn't check any of the sub-things } else { // they checked some unset($options["top"]); // don't need this // implode() on $options would be a reasonable idea } } Edited October 3, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/269011-sending-multiple-checkbox-arrays-to-email/#findComment-1382551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.