vendredi 30 novembre 2018

Drop-down menu, redirect dynamically to a link based on choice. When submit button is pressed

The change required in home page search form: For example, if I search for an investment advisor in Bengaluru,

right now its shows the URL: https://finvizer.com/?swoof=1&post_type=product&product_cat=investment-advisor-bengaluru

This need to change to: https://finvizer.com/investment-advisers-in-bengaluru/

Code: First one is in functions.php

        <div class="header-search-form"> 
            <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" name="serchvalidformhome" id="serchvalidformhome" onsubmit="return serch_validate_home();"> 
                <input type="hidden" name="swoof" id="swoofhm" value="1" /> 
                <input type="hidden" name="post_type" id="post_typehm" value="product" />   
                <div class="i-would-lik-cls">      
                <?php  $terms = get_terms( 'locationfilter',array('hide_empty' => 0, 'orderby' => 'ASC')); ?>                    
                <span class="srch-frm-home-temp-one">I need a</span> 
                <select  id="servicehm" style="width:100%"> 
                    <option value="">Choose a Service...</option> 
                    <option value="financial-planner-">Financial Planner</option>        
                    <option value="investment-advisor-">Investment Adviser</option>                
                    <option value="wealth-advisor-">Wealth Adviser</option>                        
                </select >   
                </div>                   
                <span class="srch-frm-home-temp-two">in</span> 
                 <div class="annual-incom-cls">                   
                <select id="locationfilterhm" style="width:100%" "> 
                    <option value="">Location</option> 
                    <option value="ahmedabad">Ahmedabad</option>        
                    <option value="bengaluru">Bengaluru</option>                
                    <option value="chennai">Chennai</option> 
                    <option value="delhi">Delhi</option> 
                    <option value="gurgaon">Gurgaon</option> 
                    <option value="hyderabad">Hyderabad</option> 
                    <option value="indore">Indore</option>    
                    <option value="kolkata">Kolkata</option>    
                    <option value="kochi">Kochi</option>    
                    <option value="mumbai">Mumbai</option> 
                    <option value="pune">Pune</option>                
                    <option value="surat">Surat</option>        
                </select >   
                </div>    

                <input name="product_cat" id="product_cathm" value="" type="hidden" />   
                <div class="prod-serh"> 
                    <button type="submit">search</button> 
                </div> 

            </form> 
        </div>            
    </div>   

</div> 
<div style="clear:both;"></div> 
     <?php    
$ReturnString = ob_get_contents(); ob_end_clean(); return $ReturnString; 
   } 

The second one is in footer.php

   function serch_validate_home(){ 
     var ser = jQuery("#servicehm").val(); 
     var loct = jQuery("#locationfilterhm").val(); 
       if( ser!='' && loct!=''){ 
         var srch =ser+loct; 
           jQuery("#product_cathm").val(srch); 
           document.serchvalidformhome.submit(); 
             } 
           return false; 
              }




Aucun commentaire:

Enregistrer un commentaire