Forum Moderators: coopster
Until now, when someone submits the form without entering any data, I have been returning a 200 OK header, and redirecting the user to the site homepage, so that the user can try again. I now read that this could cause problems, especially with Googlebot, and that I should be returning a 404 Not Found instead.
So here is my confusion:
User doesn't enter anything - I have to return something. But what? I do want to return the page he was on, so that he can try again, possibly adding a "try again" message. But what header code should I be returning?
Thanks.
Hope that makes sense and I didn't miss your point. :)
empty searches should shoe "please enter a search term" and then redisplay the search for. There is no need to redirect as it should send a 200 and allow them to search again on that page.
at the top of your search results page (or somewhere on the page) you should always have the form there as well.
Another option is to return a default set of pages if nothing is entered. You have your message at the top of them saying there was nothing entered and then have a list of pages/products that you want to push below that.
Both javascript and PHP validation.
Javascript is for the user because, well the vast majority of them have javascript on and it's always a nuisance to click on a form, wait a bit and then the page shows up again because you forgot something. Javascript is instant.
On the downside, it's easy for a hacker to copy your page, remove the js validation, and use the form without it, so the form needs to be validated in php as well.