Forum Moderators: open
I have a site that links to some news articles, and as you probably know most news articles are dynamic pages with multiple values in the querystring, like this:
examplenewsite.com?news=this&articleid=123&so-on&soforth...
My problem is when I try to validate my pages through W3C, any pages that link to these news sources don't validate because it doesn't like the "&" sign in the querystring of the link and tells me to use & instead - this may DISPLAY the same as "&" but it is not the same in Querystring data and when I replace & with & in the URLs I link to they don't work properly.
So how do I get around this? I want to make my pages validate, but not really sure what to do about this.
& should work, even in a querystring. Are you sure you had the ";" on the end? That's something I seem to forget fairly often. If the ";" is there, can you post the bit of code that's giving you the error? There might be issues elsewhere in that line of code that's causing problems.
If I link to example.com?test=true&test2=true the server receives the following:
Test = True
Test2 = True
If I change the link to use an & like this:
example.com?test=true&test2=true
The server sees this instead:
Test = True
amp;test2 = True
The server is expecting the variable "test" not amp;test. Using W3C's recommendation doesn't work. I'm not new to HTML or programming, just new to W3C's way of doing things. There isn't a problem with my link.
Which DTD version are you using? What character encoding are you using?
This is an interesting one! The first thing that I think you should do is to create a temporary version of the page and remove all URL encoding from the links. Try validating this page. If it validates then you are on track.
Next, it may be worth reading this Form Submission section [w3.org] of the HTML4.01 spec.
It's worth remembering that the W3C are big fans of sticky URIs - that is, URLs that don't change. It is not reflective of large eCommerce/news sites , many of which don't use that method... It's also worth noting that it is possible to have a very large site with sticky URIs, just look at the URL format of any WebmasterWorld page!
&something is not the same as &something
If you look at the source of this very page you are reading, you will see a url with an & in it:
href="/stickymail.cgi?action=enter&activefolder=inbox"
So the method works. And is a generally used one.
If it isn't working on your server, we'd need more details on what software you use to turn a URL into variables. Perhaps the solution lies there.
If my link is a normal link like <a href="whatever"> using & produces the same results as using &. If my link is part of a Javascript document.write though (as some of them were), that's where the problem was coming up.
When I use Javascript document.write to write out an <a href=whatever> line, replacing & with & in that line actually sends & to the remote server instead of &, and the remote server didn't know what to look for. It was looking for a variable named "articleid" defined by "&articleid=" but using the & in place of & in the document.write javascript link was actually making the server say that articleid was missing because it was receiving "amp;articleid" instead. Weird.
document.write('index.php?one=true&two=true'); shouldnt cause any validation errors. Id like to know exactly what line that didnt match the W3 specs and your server side language in the first place.
thanx