2

I have this search form in my drupal site.

<form id="mysearch" method="get" action="<?php echo $base_url.'/search/node/'; ?>">
   <input type="text" maxlength="150" id="search" name="s" class="input">
   <input type="submit" value="Search" class="button">
</form>

I have problem is that when I am submit the form it will pass the query like that

http://mysite.com/search/node/?s=xyz

Here I would like to change the URL something like this to search in my site.

http://mysite.com/search/node/xyz

Can anyone help me how can i achieve this thing.

I have put this code for URL Change:

$("#adminbarsearch").submit(function(e) {
    $url = $("#adminbarsearch").attr("action") + $( "input:first" ).val();
    e.preventDefault();
    window.location.href = $url;
});

Instead of this Can we change the URL by using the .htaccess

1
  • jQuery code is working fine.
    – AshwinP
    Commented Sep 18, 2013 at 5:39

1 Answer 1

1

If you use the default search block for Drupal, it will give you the functionality you need.

EDIT: Go to Structure > Blocks and enable your Search Form Block by adding it to a region.

If you perform a search using your default search block, it will redirect to a path in the format /search/node/QUERY where QUERY is what you are searching for.

By default the search form outputs (for example):

<div class="block-wrapper">
    <div class="block-container">
        <div class="block">
            <div class="content">
                <form action="/" method="post" id="search-block-form" accept-charset="UTF-8">
                <div>
                    <div class="container-inline">
                        <h2 class="element-invisible">Search form</h2>
                            <div class="form-item form-type-textfield form-item-search-block-form">
                                <label class="element-invisible" for="edit-search-block-form--2">Search</label>
                                <input title="Enter the terms you wish to search for." type="text" id="edit-search-block-form--2" name="search_block_form" value="" size="15" maxlength="128" class="form-text">
                            </div>
                            <div class="form-actions form-wrapper" id="edit-actions">
                                <input type="submit" id="edit-submit" name="op" value="Search" class="form-submit">
                            </div>
                            <input type="hidden" name="form_build_id" value="form-4gEUIDHcVH7lHHH3JpkfkVs9xBmPhHXdDQAMFMF9dHA">
                            <input type="hidden" name="form_token" value="afNo5gRQlaauXmqeZYDf80o5dEwKlg0VP6U-Ir8-p6k">
                            <input type="hidden" name="form_id" value="search_block_form">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

Now if I search for "test", it redirects to /search/node/test

2
  • Can you explain more How I can pass param in querystring without "?"
    – AshwinP
    Commented Sep 19, 2013 at 4:42
  • I've added more info to my answer Commented Sep 19, 2013 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.