Search bar in HTML - html

I have a search form, which redirects to the result. If that page does not exist, I want to display a 404 error. How can I do that?
My code
<center>
<input name="txtSearch" maxlength="12" size="25" type="text" class="field" id="txtSearch" />
<div> </div>
<div class="button" style="display:inline-block">
<a onclick='window.location.href="" + document.getElementById("txtSearch").value;'>
Submit
</a>
</div>
</center>

Firstly, it appears, that there are some strong points that are wrong in your idea and possibly understanding of search. As your post and code shows, you only allow users to search for specific things. Correct me, if I'm wrong and your code operates in other ways, but..
Imagine this: a 10 year old boy from Kenya ends up on your site - how is he supposed to know what content your site contains? Or if he does, how is he going to try and find it? Yup, he uses search.
The first hit he gets, is a 404, because he searched for something that does not exist, and does not know that your site only allows to search for specific things, that exist. He leaves your site, unable to find the content he wanted.
This is not search's function. Search should allow you to search for everything, display a list of all possible results, and a polite error if none are found - definately not reditrect to a specific page immediately - instead, a generic page for all searches, or serve a 404 if said super-specific page does not exist.
I reccommend you look into Algolia or other similar products to facilitate search.
To fix your question's problem(s), however...
You have a missing quotation mark at the class declaration of the button div. Will edit the Q to fix that.
You really, really need to use indendation. It will make your code so much easier to read, and better and more appealing for others to help you. Will edit that aswell.
What you need, is a .htaccess file in your project root, with a defined 404 page, at the very minimum. Something like this, edited, to fit your 404 error page path and name. You will design and develop your 404 page as any other page. This will, hovever apply to ALL of your missing pages, so style and build it's content appropriately (see why a search results page is better, now?).
ErrorDocument 404 /404.html
If you happen to use nginx instead of apache, do this instead in your server configuration:
error_page 404 /404.html;
Alternatively, you could build a form around the search, and send the query string (which is a fancy word for the string the user searches for) to some PHP script of yours, which could determine if there are results to show, or not and display appropriate content - again, this could also be done with Algolia or similar - just parse and feed it your content in an appropriate form.

Related

Why is my anchor href path, appending to the URL?

I'm utterly baffled by the following situation I find myself in and truthfully, I have no idea why the following is occurring or how to solve the issue.
Here's what's happening;
I have the following anchor;
<a href=”https://www.google.com/intl/en/policies/terms”
rel="nofollow"
target="_blank">
Terms
</a>
If the user clicks this anchor it results in the following URL:
https://www.example.com/contact/"https:/policies.google.com/terms
Naturally I was expecting the following URL to be loaded;
https://policies.google.com/terms
At first I thought it might be a syntax error, somewhere, so pulled the anchors and checked the code. I can't see any errors anywhere. From there, I tested other links in the page. (All are working fine.) So I thought 'well if they are working, maybe it was a typo in the code?', I rewrote the anchors and the same issue still occurs (strange).
So my second thought was the URL has to be weird somehow, so I used a couple of substitutes,
www.google.com, www.youtube.com, and www.facebook.com. All URLs resulted in the same result. Is the target href="" simply being appended to the URL?
I'm not doing anything fancy with my URLs, or JavaScript so why is this occurring? Has anyone ever encountered this? Or maybe a better question would be: How would one debug something like this?
You used incorrect double quotation marks. Take a look very closely at the HTML tags below:
<p class="text-muted">We'll get back to you within 1-2 business days.</p>
<p class="small text-muted">(This site is protected by reCAPTCHA and the <br>Google
Privacy Policy and
Terms of Service apply.)</p>
The quote used in p tag is " and it is different with the one used in the a tag, which is ”.
You need to replace it with ".
<p class="text-muted">We'll get back to you within 1-2 business days.</p>
<p class="small text-muted">(This site is protected by reCAPTCHA and the <br>Google
Privacy Policy and
Terms of Service apply.)</p>

How do I auto-fill in this textbox at the US govt website via the URL?

I'm trying to embed a value into the textbox at the USCIS government website to check my application status number. Suppose it's LIN1234. After inspecting the element of the webpage I see that the HTML wrapper for the textbox is:
<input id="receipt_number" name="appReceiptNum" class="form-control textbox initial-focus" maxlength="13" type="text">
I tried opening up this URL with a suffix added on, but to no avail:
https://egov.uscis.gov/casestatus/landing.do?receipt_num=LIN1234
Is there a way to to this?
Before that, you must understand what means adding ?receipt_num=LIN1234 to the url.
When sending a request (By default and in this context) from your browser, it'll be a GET request (see here) where you send as a get argument your receipt number, setting its key to receipt_num.
What is done to this data on the server side, however, is up to itself.
Just understand that unless the server is made to auto-fill the field with that value in case it receives it, it won't do anything except sending some more data.
I think you want to load this page in your browser with auto-filled field.
In that case you should look into extensions for your browser that would do that automatically.
You probably won't be able to embed a value into the textbox... Just because you are sending values by GET (which is what the landing.do?receipt_num=LIN1234 syntax is doing) doesn't mean that they have something set up to process it, so the GET variable will probably not do anything.
You might be able to see how their URLs work ordinarily, what the page URL that you are aiming to land on looks like, and either decode something from that or set a bookmark there. That said, if they are submitting that data via POST (which they probably are, for security reasons), that probably won't work.
I would suggest looking at reputable form-filling plugins for your web browser, if that's an option. That might allow you to work around that.

URL#whatever issue with length of #tag

Here's a question i'm finding hard to answer with google and seem to be having problems with it on my site.
I am encoding/decoding user id's just to confuse matters and would like to link to parts of a page using anchors
Thing is.. My encryption is making a nice secure long string but I think there must be a limit to the length of the # anchor names because it works when its shorter, but not when its longer.
Does this seem to be true?
An example of the hash tag url is http://wgwegw.co.uk/wegweg/protected/view-game/wegweg/platform#x243j3f41684w2w2m594n416
For example i have a link:
Go to comment
When i click on it.. it opens up using HTACCESS file redirects. if i use javascript window.hash it returns the hash so i imagine the hash code is not affected by the htaccess redirects.
I land on the page: http://.co.uk//protected/view-game/*/platform#y213j3f41684w2w2m594n416
On that page in html is an anchor name: <a name="y213j3f41684w2w2m594n416"></a>
It does not skip to that part of the page?
OK here you go.
You won't believe this but I have suffixed an 'a' and now it works.
What on earth?
EDITED//
Could it be because i have an id and a name that equal the same? so i have a
<div id = "y213j3f41684w2w2m594n416">
and I have a
<a name = "y213j3f41684w2w2m594n416" />
So when i attach a to the end of the name.. it no longer is the same as the id and thus doesn't get confused?
EDITED//
If I try this on W3 example tweaks it still works so it can't be that?
Aghh now it's fixed i am desperate to know why it's working.

Using the POST Method with HTML Anchor Tags

I am certain the answer will be 'NO', but I wanted to ask anyway just
incase I have missed something.
Everyone knows that one pass data to a page in an anchor tag by using
the GET method:
What I am wondering is if there was a way to do the same thing, but use
the POST Method instead?
My purpose in doing so is to keep the URLs the user sees clean by not
putting anything in them that they do not need to see.
This has nothing to do with security concerns as I already know there
would be ways to obtain the data being passed.
If the answer is indeed no, then what methods do people use to pass data
when there is a desire to keep the URLs clean? Cookies? Something else?
and how to deal with the scenarios when the URL length exceeds the permissible GET request length
I am facing this issue while implementing sorting/pagination with displaytag, all the request parameters are appending in the sort/pagination url which is more then the permissible length of the GET request.
You could do something like this:
<form method="post" action="target.html">
<input type="hidden" name="name" value="value" />
<a onclick="this.parentNode.submit();">click here</a>
</form>
This behaviour is specific to display tag library. It allows for easily bookmarkable search results. If you really intend to change this to make use of POST, then you'd need to rewrite the display tag library or bring in some jQuery to manipulate the links.
The remnant of your questions boils nowhere. If you want GET (idempotent requests, bookmarkable URLs, searchbot-crawable URLs, etc), then use GET. If you want POST (non-idempotent requests, non-bookmarkable URLs, non-crawlable URLs, etc), then use POST.
Usually, POST is mandatory when the request can modify the data in the server. Think of a SQL INSERT, UPDATE, DELETE, etc. You certainly won't make this kind of requests GET. Imagine that you've a table with all "delete row" links which do GET and then a searchbot comes along...
You can use javascript. On onclick of link do form.submit
The only way I know of to deal with lenghty URL is to instead use POST.
You may create a temporary form and submit it while onclick event of <a> tag.
It will work as post ,the name value can be through anchor tag and value of name="" can be access to $_POST[] globl var

Facebook like buttons erroneously handled as one

I've implemented the like button on my WP blog, but for some reason some of them (not all of them) are interpreted as being the same button. If I press like, I will also like the ones that is interpreted as the same. I can't figure out why. There are several other problems with what is shared on Facebook, but I think those problems are connected to this one.
It worked great for a few days, then I started getting an error each time I pressed the like button. After fiddling with the og:type value the error disappeared, but instead now I get this strange behaviour.
My implementation is so simple, I can't really think of any causes:
<div class="fb-like"><fb:like href="<?php the_permalink();?>" show_faces="true" width="600" font="arial"></fb:like></div>
I've found that the behaviour changes depending on what og:type I define in the header section, but with no value producing the correct result.
the blog can be seen at http://blog.parkov.dk/ (in Danish, though).
Anyone has experience with this?
Remove the href parameter and instead use the Open Graph meta tags. I see that you are using them but some required tags are missing:
og:title
og:url
IMPORTANT NOTE:
For the homepage use blog as og:type!