Jump to content

Recommended Posts

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

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 by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.