This is driving me up the wall. I obviously don\'t understand soemthing pretty fundamental, I\'m hoping someone can shed light on the matter.
The parts of your page are the core behind the search function:
JavaScript:
function handleThis(formElm){
window.location="http://syndex.me/tagged/"+formElm.q.value+"";
return false;
}
HTML:
<form onsubmit="return handleThis(this)" >
<input type="text" name="q" value=""/>
</form>
An event listener is bound to your form, using onsubmit="return handleThis(this)".
onsubmit is triggered when the user presses enter, or hits the Search button.onsubmit attribute (aka event handler), you notice return handleThis(this). This function (which is defined at the same page; look ahead) is called with the this keyword as first argument. this from within the context of an event handler refers to the event listener's owner element, in this case <form>.handleThis(formElm), you notice "http://syndex.me/tagged/"+formElm.q.value. formElm.q refers to an input element called q within the form element. formElem.q.value holds the value of the input element, which contains the search keywords. The just constructed URL is assigned to window.location, which initiates a new request to http://syndex.me/tagged/search_terms.return false. Inside the onsubmit event handler, you've seen return handleThis(this). The return value of handleThis is passed to the onsubmit event handler. So, the statement equals onsubmit="return false". This means that the form does not submit itself any more.return false. When an error occurs, or if a user has disabled JavaScript, the form will submit itself to the URL as defined at action. Because the action attribute is not specified, the page's current URL is used instead, http://syndex.me/ in this case. All named form elements are added to the request, so the final URL will be http://syndex.me/?q=search_termsTo get back to your question, <form action="/tagged"method="get">`:
onsubmit event handler.onsubmit event handler is not specified, the HTML form will be submitted by the browser (an imaginary onsubmit handler would equal return true./tagged, which translates to a file called "tagged" at the ROOT directory of your host. In this case: http://syndex.me/tagged?q=search_terms. (q=.. is a result from the input element called q).action to /tagged/ instead of /tagged, the submitted form will request the following page: http://syndex.me/tagged/?q=search_termsWhen you change /tagged to /search, your form submits to http://syndex.me/search?q=.... As seen through the headers, this location redirects to http://syndex.me/search/....
This behaviour is likely achieved using a rule defined in .htaccess:
RewriteEngine On
RewriteRule ^/search\?q=(.*)$ /search/$1 [L,R=301]
Understood?