Forum Moderators: open

Message Too Old, No Replies

W3C Validation Question

Confused about & in Querystring

         

Newsman

12:42 am on May 15, 2004 (gmt 0)

10+ Year Member



Hi everyone,

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.

photon

1:37 am on May 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Newsman, welcome to WebmasterWorld!

&
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.

Newsman

1:39 am on May 15, 2004 (gmt 0)

10+ Year Member



It doesn't work that way with a querystring, the script on the other side isn't recognizing the actual value. Here's an example:

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.

Newsman

4:15 pm on May 15, 2004 (gmt 0)

10+ Year Member



Still no one has an answer to this question?

PCInk

4:19 pm on May 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should work for links in HTML only.

It does not work if you type & into the browser's address bar.

BlobFisk

6:44 pm on May 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, newsman!

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!

Newsman

6:38 am on May 16, 2004 (gmt 0)

10+ Year Member



None of this really has anything to do with my question ... my page is fine until I add links to news articles that contain "&something=something" in the querystring. Using &something=something DOES NOT WORK - the page validates when I do that, but the link to the article doesn't work. See my above post for how the receiving server (which are major news sites and I have no control over their structure) handles requests.

&something is not the same as &something

victor

7:58 am on May 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



newsman,

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.

BlobFisk

12:25 pm on May 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it looks like there is a problem with your link so. The example you posted:

examplenewsite.com?news=this&articleid=123&so-on&soforth...

Has no page specified. Should there be a page in there, eg:

examplenewsite.com/page.cgi?news=this&articleid=123&so-on&soforth...

HTH

Newsman

3:24 pm on May 16, 2004 (gmt 0)

10+ Year Member



I think I figured out the problem, the results are really interesting though... was anyone else aware of this?

If my link is a normal link like <a href="whatever"> using &amp; 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 &amp; in that line actually sends &amp; 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 &amp; 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.

RonPK

4:24 pm on May 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Newsman, could you post the exact document.write statement (anonymised, if necessary)? I'm curious what went wrong...

Bonusbana

3:03 pm on May 17, 2004 (gmt 0)

10+ Year Member



Yes, Im also curious. And as for the validation, last time I checked the W3 validator doesnt parse javascript. So writing a
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

g1smd

10:32 pm on May 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Any update on this?