0
<form action="includes/search.php" method="get">
    <input name="search" type="text" class="search" /> 
    <input type="submit" value="Search" />
</form>

I want user to type text in textfield and when he hits enter it will paste it in URL.

Currently url is: http://randomsite.com/includes/search.php?search=adsasd

But it should be like this: http://randomsite.com/beta/match/adsasd

2
  • You need htaccess mod_rewrite. Search for that keyword on SO Commented Feb 11, 2014 at 6:03
  • Okay. How can I remove "?search=" before value? Commented Feb 11, 2014 at 6:04

1 Answer 1

2

You are currently submitting the form as a GET request to the includes/search.php page.

Try calling a JavaScript function instead:

<form id="search-form" onsubmit="return performSearch()">
  <input name="search" type="text" class="search" id="search-query" />
  <input type="submit" value="Search" />
</form>

Then collect the information from each field, and redirect to the desired URL in that function:

function makeSearch()
{
  var searchQuery = document.getElementById("search-query").value;
  var searchURL = 'http://randomsite.com/beta/match/' + searchQuery;
  window.location.assign(searchURL);
  return false;
}

NOTE: Untested, but should work or be very close to a solution.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.