Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with a custom Wordpress form

    I have a custom search form on a Wordpress real estate website that is supposed to display properties based on options chosen in the different fields in the search form. The fields are: City, Area, Price Range, Age, Property Type, Size, and Bedrooms. This data is gotten from custom fields.

    Right now the form doesn't work properly. The only criteria that get included in the search are the "Price" and "Area" fields. The rest just don't get included as search paramaters.

    Any help with this issue would be appreciated. Here is a link to the code for the main search form: http://pastebin.com/5dj16Atj

    The code for the include is below:

    PHP Code:
    <?php
    $isshow_search 
    0;
    if(
    is_home() && $_REQUEST['search']!='')
    {
        
    $isshow_search 1;
    }
    if(
    is_home() && $_REQUEST['page']!='')
    {
        
    $isshow_search 1;
    }
    elseif(!
    is_home())
    {
        
    $isshow_search 1;
    }

     
    function 
    city_list()
    {
        global 
    $wpdb;
        
    $query $wpdb->get_results("SELECT id,name FROM $wpdb->cities");
        foreach((array)
    $query as $city)
        {
            echo 
    "<option value='".$city->id."'>".$city->name."</option>";
        }
    }

    ?>
     <div id="propertysearchoptions"  <?php if($isshow_search){?> style="display:none;" <?php }?> >
    <div class="search ">
         <form method="get" id="srch_frm" name="srch_frm" action="<?php echo get_option('siteurl');?>">
         <input type="hidden" id="s" name="s" value="search">
        <input type="hidden" name="search" value="search" />
         <div class="search_form">          
             <div class="search_row clearfix">
                 <label class="for">I want to: </label>  
                <input name="srch_type" <?php if($_REQUEST['srch_type']=='Sale'){ echo 'checked="checked"';}?> id="srch_type_buy" type="radio" 
                value="Sale" class="radio" /> <span>Buy a property</span>  
                <input name="srch_type" <?php if($_REQUEST['srch_type']=='Rent'){ echo 'checked="checked"';}?> id="srch_type_rent" type="radio"  value="Rent" class="radio" /><span>Rent a property</span>
                <input name="srch_type" <?php if($_REQUEST['srch_type']==''){ echo 'checked="checked"';}?> id="srch_type_all" type="radio" value="" class="radio" /> <span>Search all properties</span>  
             </div>
             
             
             
           <div class="search_row clearfix">
                <label> <?php echo "City"//_e(SEARCH_LOCATION_TEXT); ?> : </label>   
                    <select name="srch_city" id="srch_city" onchange="" class="fl select">
                    <option value=""><?php echo "Select City" ?></option>                
                    <?php city_list(); ?>
                   </select>
                    
                
                <label class="spacer" > <?php echo "Area"?>  : </label>   
                    <select name="srch_location" id="srch_location" onchange="" class="select">
                    <option value=""> Select Area </option>
                      <?php echo get_location_dl($_REQUEST['srch_location']);?>
                   </select>
                
               </div>
               
               
               
             <script type="text/javascript">
                 //Change Location setings
                     var srch_city = $("#srch_city");
                    srch_city.change(function()
                    {
                        id = srch_city.val();
                        $("#srch_location").empty().html("<option value=''>Select Area</option>");
                        $.ajax(
                        {
                            type: "GET",
                            url: "<?php bloginfo('template_directory'); ?>/library/includes/get_location.php",
                            data: "id="+id,
                            cache: false,
                            async: false,
                            success: function(result) 
                            {
                                $("#srch_location").append(result);
                            }
                        })
                    });
                    
                    $(document).ready(function()
                    {
                        var price = $("#srch_price");
                        $(":radio").click(function()
                        {
                            if (this.id == "srch_type_buy")
                            {
                                price.empty();    
                                price.append("<option>All Price Ranges In =N=</option><option value='1000000-10000000'>1000000-10000000</option><option value='10000000-50000000'>10000000-50000000</option><option value='50000000-200000000'>50000000-200000000</option><option value='200000000-1000000000'>200000000-1000000000</option><option value='1000000000+'>1000000000+</option>");
                            }
                            else if (this.id == "srch_type_rent")
                            {
                                price.empty();    
                                price.append("<option>All Price Ranges In =N=</option><option value='100000-1000000'>100000-1000000</option><option value='1000000-5000000'>1000000-5000000</option><option value='5000000-20000000'>5000000-20000000</option><option value='20000000+'>20000000+</option>");
                            }
                            else if (this.id == "srch_type_all")
                            {
                                price.empty();    
                                price.append("<option>All Price Ranges In =N=</option><option value='100000-1000000'>100000-1000000</option><option value='1000000-10000000'>1000000-10000000</option><option value='10000000-50000000'>10000000-50000000</option><option value='50000000-200000000'>50000000-200000000</option><option value='200000000-1000000000'>200000000-1000000000</option><option value='1000000000+'>1000000000+</option>");
                            }
                        });
                    });
            
                 </script>            
              
              <div class="search_row clearfix">
                <label><?php _e(SEARCH_PRICE_RANGE_TEXT); ?> : </label> 
                  <select name="srch_price" id="srch_price" onchange="" class="fl select">
                     
                 <option>All Price Ranges In =N=</option>
                   <option value='100000-1000000'>100000-1000000</option>
                   <option value='1000000-10000000'>1000000-10000000</option>
                   <option value='10000000-50000000'>10000000-50000000</option>
                   <option value='50000000-200000000'>50000000-200000000</option>
                   <option value='200000000-1000000000'>200000000-1000000000</option>
                   <option value='1000000000+'>1000000000+</option>
                    
                    
                   </select>
                
                
                
                
                   
                    <div style="margin-left:400px">
                    <span style="color:#FFF; font-weight:normal">Age:</span>
                    <select name="srch_age" id="srch_age" onchange="" class="select">
                     <option value=""><?php echo "Select Property Age" ?></option>                
                    <option value="1-2">1 - 2yrs</option>
                    <option value="3-5">3 - 5yrs</option>
                    <option value="6-10">6 - 10yrs</option>
                    <option value="11-25">11 - 25yrs</option>
                    <option value="26-50">26 - 50yrs</option>
                    <option value="50+">50+yrs</option>
                   </select>
                </div>
                   
              </div>
              
              
              <div class="search_row clearfix">
                <label><?php echo "Property Type"?> : </label>   
                    <select name="srch_ptype" id="srch_ptype" onchange="" class="fl select">
                     <option value>Search Property Type </option>
                    <option value="Bungalow">Bungalow</option>
                    <option value="Duplex Detached">Duplex Detached</option>
                    <option value="Duplex (semi-detached)">Duplex (semi-detached)</option>
                    <option value="Flat">Flat</option>
                    <option value="Townhouse">Townhouse</option>
                    <option value="Boys Quarters">Boys Quarters</option>
                    <option value="Office Space">Office Space</option>
                    <option value="Warehouse">Warehouse</option>
                    <option value="Land">Land</option>
                    <option value="New development">New development</option>
                   </select>
                
                     
                 
                <label class="spacer" > <?php echo "Size";//_e(SEARCH_AREA_TEXT); ?> (<?php echo get_area_unit();?>) : </label>   
                    <select name="srch_area" id="srch_area" onchange="" class="select">
                     <option value=""><?php _e(SEARCH_ALL_AREA_TEXT); ?></option>                
                    <?php get_area_range_dl($_REQUEST['srch_area']);?>
                   </select>    
                  
                   
              </div>
              
              
               <div class="search_row clearfix">
               
                <label><?php _e(SEARCH_BEDROOMS_TEXT); ?> : </label>   
                    <select name="srch_bedrooms" id="srch_bedrooms" onchange="" class="fl select select_s">
                     <option value=""><?php _e(SELECT_ALL_BEDROOMS_TEXT); ?> </option>
                     <?php echo get_bedroom_dl($_REQUEST['srch_bedrooms']);?>
                    <?php //echo get_category_dropdown_options(get_cat_id_from_name(get_option('ptthemes_bedroomcategory')),$_REQUEST['srch_bedrooms']);?>
                   </select>
                
                    <!-- <label class="spacer2" > <?php _e(SEARCH_BATHROOM_TEXT); ?> : </label>   
                    <select name="srch_bathroom" id="srch_bathroom" onchange="" class="fl select select_s">                            
                     <option value=""><?php _e(SELECT_ALL_BATHROOM_TEXT); ?></option>
                    <?php 
                    get_bathroom_dl
    ($_REQUEST['srch_bathroom']);
                    
    ?>
                   </select>!-->
                <div class="btncontainer" style="margin-left:270px;">
               <span class="largebuttons"><a href="javascript:search_now();" class="btn_largewhite ico_search">Search now</a></span></div>        
               </div>
             
         </div> <!-- search form--></form>
         <div class="property_id_search">
         <div class="center-aligned"><a href="map-search"><img src="<?php echo bloginfo('template_url'); ?>/images/map-icon.png" /></a></div>
         </div>
         
         
    <!-- <div class="searchbottom"></div> commented out for the time being -->



    </div>    
    </div>
    <!-- search end -->
    <script>
    function search_property()
    {
        document.search01.submit();
    }
    function search_by_id()
    {
        document.getElementById('spid').value = '';
        if(document.getElementById('srch_property_id').value)
        {
            document.getElementById('spid').value = 'property id : '+document.getElementById('srch_property_id').value;
        }else
        {
            document.getElementById('spid').value ='all properties';
        }
        document.srch_frm_by_id.submit();
    }
    function search_now()
    {
        document.getElementById('s').value = '';
        var srch_type = '';
        if(document.getElementById('srch_type_buy').checked)
        {
            var srch_type = document.getElementById('srch_type_buy').value;    
        }else
        if(document.getElementById('srch_type_rent').checked)
        {
            var srch_type = document.getElementById('srch_type_rent').value;    
        }
        var srch_price = document.getElementById('srch_price').options[document.getElementById('srch_price').selectedIndex].text;
        var srch_location = document.getElementById('srch_location').options[document.getElementById('srch_location').selectedIndex].text;
        var srch_bedrooms = document.getElementById('srch_bedrooms').options[document.getElementById('srch_bedrooms').selectedIndex].text;
        var srch_city = document.getElementById('srch_city').options[document.getElementById('srch_city').selectedIndex].text;
        //var srch_bathroom = document.getElementById('srch_bathroom').options[document.getElementById('srch_bathroom').selectedIndex].text;
        var srch_area = document.getElementById('srch_area').options[document.getElementById('srch_area').selectedIndex].text;
        //var srch_keyword = document.getElementById('srch_keyword').value;
        
        var searchfor = '';
        if(document.getElementById('srch_price').value!='')
        {
            searchfor = srch_price;
        }
        if(srch_type!='')
        {
            if(srch_type!='' && searchfor=='')
            {
                searchfor = srch_type;
            }else
            {
                searchfor = searchfor +' & '+ srch_type;
            }
        }
        
        
        //Custom City Handler
        if(document.getElementById('srch_city').value!='')
        {
            if(srch_city!='' && searchfor=='')
            {
                searchfor = srch_city;
            }else
            {
                searchfor = searchfor +' & '+ srch_city;
            }
        }
        if(document.getElementById('srch_location').value!='')
        {
            if(srch_location!='' && searchfor=='')
            {
                searchfor = srch_location;
            }else
            {
                searchfor = searchfor +' & '+ srch_location;
            }
        }
        
        
        if(document.getElementById('srch_bedrooms').value!='')
        {
            if(srch_bedrooms!='' && searchfor=='')
            {
                //searchfor = srch_bedrooms;
                if(srch_bedrooms>1)
                {
                    searchfor = srch_bedrooms+' Bedrooms';
                }else
                {
                    searchfor = srch_bedrooms+' Bedroom';
                }
            }
            
            /*else
            {
                //searchfor = searchfor +' & '+ srch_bedrooms;
                if(srch_bathroom>1)
                {
                    searchfor = searchfor +' & '+  srch_bedrooms+' Bedrooms';
                }else
                {
                    searchfor = searchfor +' & '+ srch_bedrooms+' Bedroom';
                }
            }*/
        }
        /*if(document.getElementById('srch_bathroom').value!='')
        {
            if(srch_bathroom!='' && searchfor=='')
            {
                if(srch_bathroom>1)
                {
                    searchfor = srch_bathroom+' Baths';
                }else
                {
                    searchfor = srch_bathroom+' Bath';
                }
            }else
            {
                if(srch_bathroom>1)
                {
                    searchfor = searchfor +' & '+  srch_bathroom+' Baths';
                }else
                {
                    searchfor = searchfor +' & '+ srch_bathroom+' Bath';
                }
            }
        }*/
        if(document.getElementById('srch_area').value!='')
        {
            if(srch_area!='' && searchfor=='')
            {
                searchfor = srch_area;
            }else
            {
                searchfor = searchfor +' & '+ srch_area;
            }
        }
        
        /*if(srch_keyword=='' || srch_keyword=='<?php echo CITY_STATE_ZIP_SRCH_TEXT;?>')
        {
            document.getElementById('srch_keyword').value = '';
        }
        else
        {
            if(srch_keyword!='' && searchfor=='')
            {
                searchfor = srch_keyword;
            }else
            {
                searchfor = searchfor +' & '+ srch_keyword;
            }
        }*/
        
        if(searchfor=='')
        {
            searchfor = 'all properties';
        }
        document.getElementById('s').value = searchfor;
        document.srch_frm.submit();
    }
    function show_hide_propertysearchoptions()
    {
        if(document.getElementById('propertysearchoptions').style.display == 'none')
        {
            document.getElementById('propertysearchoptions').style.display = ''
        }else
        {
            document.getElementById('propertysearchoptions').style.display = 'none';
        }
    }
    </script>
    Thanks.
    Last edited by ephi; 05-27-2012 at 11:37 AM. Reason: Added code from the main search form


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •