-3

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

right now it 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( '/' ) );

now in this peice of code, method is get and what action doing is: calling the home url of the website(i.e. http://finvizer.com) and onsubmit the function is called serch_validate_home(), which is working fine.

    ?>" 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" /> 

this inputs are form a plugin "woocommerce" which comes in url, because of this peice of code website is landing to https://finvizer.com/?swoof=1&post_type=product&product_cat=investment-advisor-bengaluru but i wanted page to be redirected https://finvizer.com/investment-advisers-in-bengaluru/

I have made them comment and tried to run and the result was http://www..finvizer.com/?product_cat=

                    <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>    

so from here, I saw there is one more input product cat, I changed it nothing(input name="") than website was redirected to https://finvizer.com/?

                <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 it's a javascript code in footer.php. This function is called by functions.php Here two variable are taking value from the form, the service value is in ser and location one is in loct.

   function serch_validate_home(){ 
     var ser = jQuery("#servicehm").val(); 
     var loct = jQuery("#locationfilterhm").val(); 
       if( ser!='' && loct!=''){ 

in this srch variable, I have already placed "in-" . it made the srch variable vale what we want (i.e. financial-planner-in-bengaluru). but it's not working without those two HTML embedded inputs which I mentioned above. And when I try with them the page gets crashed.

         var srch =ser+loct; 
           jQuery("#product_cathm").val(srch); 
           document.serchvalidformhome.submit(); 
             } 
           return false; 
              }

p.s. this code is written by another developer, which the owner has no contact with, I have been asked to redirect the page on a different link. I tried to go through each and every step as per my knowledge but got stuck. I was able to remove everything from the link and was able to redirect to https://finvizer.com/? but how should I place that srch varable instead of that "?"

batsyk
  • 1
  • 3
  • If you're expecting someone to just do this for you, you're in the wrong place. If you have a specific question about an attempt that you've made, then you need to do a better job describing how the result of your attempt failed to do what you wanted and what debugging you've already done. – Patrick Q Nov 30 '18 at 20:04
  • I don't see any specific question, please be more specific. – jesicadev18 Nov 30 '18 at 20:11
  • I have tried to explain it more precisely, in a recent edit of the question. – batsyk Dec 01 '18 at 03:49
  • @PatrickQ it's my first question here, so made few mistakes while asking, I have made changes, please see and let me know your thoughts! Thank you once more. – batsyk Dec 01 '18 at 03:55
  • @jesicadev18 made changes, please may have a look at it now. Thank you for your help. – batsyk Dec 01 '18 at 03:55

1 Answers1

0

If you want the function to activate first, put the "onsubmit" before "action" on the form.

Otherwise I think this question needs a little more info on the submit side.

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

i would suggest adding the brakets and "in-" for srch? If this doesnt help please help me understand what the "action" in the form does as well as any other important informatino needed

  • Some changes have been made to the question, you may please have look at them. thank you! for investing your time in this question. – batsyk Dec 01 '18 at 03:57