3

I am going through a webpage source and trying to figure out how a search is being executed.

Inspecting the search button and input gives me this:

<h2>Search the MySite.net Forum</h2>
<form action="?" method="post">
<p>
    <b>Search for:</b>
    <input type="text" name="s" placeholder="Search..." style='width:90%;' maxlength="255" />
</p>
<p>
    <p>Search in:</b>
    <select name="in">
        <option value="ft">forum title or text</option>
        <option value="tt">thread titles</option>
        <option value="pt">poll titles</option>
    </select>
</p>
<p>
    <input type="submit" value="Search the MySite.net Forum" />
</p>
</form>

The only available script related contains this:

$('#search-submit').click(function() { 
    var q = $('#searchq').val(); 
    if(q.match("site:mysite.net")) { return; } else { $("#searchq").val(q+ ' site:mysite.net'); }
});
  1. Can someone clarify the form attribute action="?". I'm not used to seeing that AND the POST method, I thought it was only for GET. What does it mean?
  2. I don't understand the q.match("site:mysite.net"), I am having a hard time finding the meaning of the colon ("site:mysite.net") searching a ':' is throwing me all over the place. I assumed it's searching the whole site, but that doesn't seem right. Can someone clarify this for me as well.
brentD
  • 31
  • 3
  • http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post – andrewk Dec 22 '12 at 04:56
  • Thank you, but those weren't really what I was asking. I work with .NET/C# and am on a RESTful project. I am weak in JS and jQuery, but I understand POST and GET. I dont understand action="?" and from what I've read about it, it's used when the method is defined as GET. I have used the action attribute in the past to utilize scripts, but the "?" is new to me, and the use of the "?" with a POST method is even more confusing. Thanks. – brentD Dec 22 '12 at 05:11
  • There is not nearly enough code here to describe what is happening. For one thing, this event handler is bound to `#search-submit` and it selects `#searchq`, which aren't even in your html. Can you just give the url of the site you're looking at? Also, you can use something like firebug or web inspector to see what URLs are actually being retrieved by this code, or to set breakpoints in the javascript to trace execution. – Francis Avila Dec 22 '12 at 05:38
  • Yeah, you're right Francis. There is something else going on, I figured that much out, pretty sure its PHP. Unfortunately, I can't really give away the site. I'm volunteering some time and the admin is touchy about showing his code, which is making it tough. I can't meet with him until Tuesday, so I'm burning the midnight oil and trying to figure out whats going on client side. – brentD Dec 22 '12 at 05:56

3 Answers3

3

The action attribute of the form tag just specifies the URL that the form will submit the data to.

match is a method on the string object that matches a regular expression pattern.

Jason Whitted
  • 4,059
  • 1
  • 16
  • 16
  • The form uses `POST`, which I understand to contain the values in it's body. When using `action = "post"`, how does the query get appended to the URL if it's not using `GET` to query through the address bar? – brentD Dec 22 '12 at 05:25
  • It's `method=post`, it's action is set to "?". It will not post the form data as a querystring. It will post the form data to the current url with a ? appended. Much like when you see ``. The browser does not try to navigate to #. Instead it tries to navigate to the `#`. – Jason Whitted Dec 22 '12 at 05:29
  • I think the match is looking for a string literal, so it's actually matching "site:mysite.net" and appending "site:mysite.net" to the string calling the match. I am snooping someones code and trying to figure things out. There is some hidden jQuery magic that I can't see. The function in my question is returning it to some other function I can't find. Thank you though. – brentD Dec 22 '12 at 05:34
  • You're right, typo. `method = "post"` and `action = "?"`. Sorry. – brentD Dec 22 '12 at 05:35
2

Site:yoursite is a command to google to narrow the search in its indexes to your site. Somewhere you will have a google invocation

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • That makes logical sense, although the code snippets he provided us do not actually show it is posting to google. – Jason Whitted Dec 22 '12 at 05:32
  • So this is used to search a site? I'm thinking another function is used to search the site, but that you are correct that it is a google invocation – brentD Dec 22 '12 at 05:50
0
  1. The action="?" will submit the form to the current URL, using the "?" to signify a query and appending the form data. The query is hidden because method = "post", which is ok to use in this case. Regardless of the method, the form will still submit as a query to the current URL.

  2. The match is a string literal and is returning a string containing that literal.

brentD
  • 31
  • 3