• Leo Blanchette

    (@leoclipartillustrationcom)


    Its rare that I get answers on this forum, but I’m still hopeful. Here is the problem:

    When I input a multi-word search term into the search field on my site, the space disappears between words!

    Try it – https://www.clipartillustrations.com/search-images/

    Normally there would be a little “+” sign between the words, but that is not happening — instead the space deletes and condenses the search to one word.

    Example:

    Orange Man becomes orangeman

    instead of

    orange+man

    I noticed this is directly related to permalink settings. When I switch back to default permalinks this does not happen.

    How can I stop this behavior in the most wordpress-consistent way possible? This will be a custom image search field.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    For some more explanation, here is the code that sets up the search:

    //name of search page...
    
    $page_name = 'search-images';
    
    //get the id of the search page
    
    $id = m_m_get_page_id( $page_name );
    
    //get the permalink of the search page...
    
    $search_permalink = get_permalink( $id );  
    
    ?>
    
    <!-- #access -->
    <div class="span-17 cai_header_search">
    <div id="cai_searchwrapper">
    <form id="searchform" method="get" action="<?php echo $search_permalink; ?>">
    <input type="hidden" name="page_id" value="<?php echo $id; ?>" />
    <input type="text" class="cai_search_box" name="search" value="" />
    <input type="image" src="<?php bloginfo('template_directory') ?>/images/cai_blank.gif" class="cai_searchbox_submit" value="" />
    				</form>
    			</div>
    		</div>
    
    //HERE is the resulting HTML
    
    <div class="span-17 cai_header_search">
    <div id="cai_searchwrapper">
    <form id="searchform" method="get" action="https://www.clipartillustrations.com/search-images/">
    <input type="text" class="cai_search_box" name="search" value="" />
    <input type="hidden" name="page_id" value="699" />
    <input type="image" src="https://www.clipartillustrations.com/wp-content/themes/microstock-machine/images/cai_blank.gif" class="cai_searchbox_submit" value="" />
    </form>
    </div>
    </div>

    Interestingly, when I remove the “hidden” input, nothing messes up. But that is needed in case the user switches the permalinks from the static looking url to the default dynamic one.

    I noticed that the action=”?some-dyamic-url” does not work properly so the second invisible input was added as a workaround.

    Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    As a band-aid solution I’ve just put an if-statement

    $is_dynamic = strpos( $search_permalink ,'?' );
    
    if($is_dynamic !== false){$page_invis_input = '<input type="hidden" name="page_id" value="'. $id . '" />'; }
    
    // ....
    
    <form id="searchform" method="get" action="<?php echo $search_permalink; ?>">
    	<?php if($page_invis_input){ echo $page_invis_input;} ?>
    	<input type="text" class="cai_search_box" name="search" value="" />
    	<input type="image" src="<?php bloginfo('template_directory') ?>/images/cai_blank.gif" class="cai_searchbox_submit" value="" />
    </form>

    …of course if anyone knows why my spaces were being deleted, I think I could do a cleaner fix.

    Thanks.

    The code you’ve posted here doesn’t show the exact code that handles the search. You should post the whole code, so we could see what’s going on.

    Thread Starter Leo Blanchette

    (@leoclipartillustrationcom)

    Sure. Thanks a lot for replying too! (sadly I cannot express the problem in more condensed fashion)

    I’ve been monkeying with it so a few things have changed, but more or less same problem. I may have figured out the issue. (Code below, pasted from functions file)

    #1. This is going to be an image search which taps into a special table.

    When the action=’https://www.clipartillustrations.com/?page_id=699 … it does not go to link destination (which is image search page which runs the unique image search variables)

    Hence I’ve created the rather convoluted script you see here to improvise over different permalink scenerios.

    Everything was working as expected until the mysterious problem mentioned at the opening post.

    //a get ID by page name function is necessary for our search input buttons...
    
    function m_m_get_page_id($page_name){
    	global $wpdb;
    	$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
    
    	$id = $page_name;
    
    	return $id;
    }
    
    //the main search form...
    
    function m_m_search_form( $form ) {
    
    	//Since wordpress users may have differing permalink structures, the permalink to the search page must be retrieved so the <form> "action=whatver_link" can be assigned.
    
    		//name of search page...
    
    		$page_name = 'search-images';
    
    		//get the id of the search page
    
    		$id = m_m_get_page_id( $page_name );
    
    		//get the permalink of the search page...
    
    		$search_permalink = get_permalink( $id );  
    
    		$is_dynamic = strpos( $search_permalink ,'?' );
    
    		if($is_dynamic !== false)			
    
    			{$page_invis_input = '<input type="hidden" name="page_id" value="'. $id . '" />';
    
    			 $form_action = home_url( '/' );
    
    			} else 
    
    			{$form_action = $search_permalink;	 $page_invis_input = ''; }
    
        $form = '<form role="search" method="get" id="searchform" action="' . $form_action . '" >
        ' . $page_invis_input . '
        <input type="text" class="cai_search_box" value="' . get_search_query() . '" name="search" id="s" />
    	<input type="image" id="searchsubmit" src="' .  get_template_directory_uri() . '/images/cai_blank.gif" class="cai_searchbox_submit" value="" />
    
        </form>';
    
        return $form;
    }
    
    add_filter( 'get_search_form', 'm_m_search_form' );
    
    ?>

    Did you ever figure out anymore information on this? I’m guessing that the WordPress permalinks are stripping out the spaces because it doesn’t understand that the variables are dynamic. So far this is the only thread I’ve been able to find the problem and any discussion on it is much appreciated. Thanks!

    cbishop2011

    (@cbishop2011)

    I am having the same problem and at the moment I have determined that there is an internal redirect that is happening that is causing the GET variable to have it’s spaces stripped.

    I have a local copy that works fine. It uses permalinks. The exact hosted copy is having the problem. Using firebug I can see on the hosted copy there is a request for: GET /search/?term=this+that

    Then there is a second request: GET /search/?term=thisthat
    right after the first request.

    Locally this doesn’t happen.

    I’m still investigating.

    cbishop2011

    (@cbishop2011)

    So locally from the home page if I type in “this that” in the search. It will send a request GET /?term=this+that “200” and then I am redirected to /search/?term=this+that

    But on the hosted copy I get a request: GET /?term=this+that “301”
    then a request: GET /search/?term=thisthat “200”.

    I would guess that it is the permalink redirect that is causing the problem.

    cbishop2011

    (@cbishop2011)

    Ok, solved the issue for myself.

    The copy on the host was submitting to the wrong page. It was suppose to submit to the /search/ page but it went else where but because the GET variable term was set, and wordpress could not find the page it was trying to submit to it redirected to the /search/ page so I was seeing the page I was expecting to see but I was getting there indirectly.

    Ok so I fixed the form submission. It now submits to /search/ and it works fine. Unfortunately this doesn’t help people who expect a redirect to take place.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Spaces disappeared from GET url variables’ is closed to new replies.