Bad ID reference error

For technical support and bug reports for all editions of CSS HTML Validator, including htmlval for Linux and Mac.
Post Reply
JimM77
Rank 0 - Newcomer
Posts: 8
Joined: Tue Nov 08, 2022 2:27 am

Bad ID reference error

Post by JimM77 »

Many thanks again for a fantastic app.

I have a problem where I have an ID on most pages, that is inserted in a section of code by PHP include. On these pages, there is a href to that ID on the same page (i.e, the ref begins with href="#...). When I run the batch wizard, I get a bunch of errors: the wizard says:
not found in document file:///... (linked from ....).


If I check the details for a file, the message is:
Bad reference. Does this document contain an element with an ID of "CmtBox"? This link should be removed or it should link to a location in the document that is specified by the attribute id="CmtBox". ...


There are no other errors reported. But if I run one of these files through the Validator individually, the links are reported as OK. On the actual files in the browser, everything is working as it should. The pages are also working perfectly on the website itself (with the href either directly in file or in PHP include).

I am using version v20.0400, but I have checked with the latest version trial and it has the same problem.

I have found that if I put the href into a PHP include so that it does not occur in the document itself but only by a PHP include, the problem disappears. However, since the actual part of code is only 127 characters and cannot be incorporated in an already existing PHP include, it's not the ideal way to solve the problem. Note that while there are two hrefs to the same ID in that small bit of code (so it shows 2 errors for each file) I tried removing one, but the problem was still there.
Attachments
Screenshot3.png
Screenshot3.png (26.15 KiB) Viewed 3476 times
Screenshot2.png
Screenshot2.png (35.82 KiB) Viewed 3476 times
Screenshot1.png
Screenshot1.png (22.72 KiB) Viewed 3476 times
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: ID reference errors

Post by Albert Wiersch »

Hello,

I think the easiest way to solve this issue is to just filter that error out by disabling the message using 'exact text match', because you know it's not really an error based on how your pages are constructed.

You can do this by right-clicking on the error message when displayed in CSS HTML Validator's Results Window and choose 'Message Options > Disable using Exact Text Match'. That will disable it in the Batch Wizard as well.

This will filter out any validator messages whose text exactly matches the message you disabled.

I hope this helps. Please let me know if you have any more questions.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
JimM77
Rank 0 - Newcomer
Posts: 8
Joined: Tue Nov 08, 2022 2:27 am

Re: Bad ID reference error

Post by JimM77 »

Thanks for the reply. Unfortunately, I only get a "not found in document" error with the batch wizard, which doesn't have that option. I made up a file with a deliberate CmtBox ref but no ID, and on individual test, and it has no error or warnings, and the link comes up as "not found in document" with no associated message and no option to disable it in any way. I also tried adding in the link path options a path to ignore as *#Cmtbox and *Cmtbox and similar combinations but none worked.
Attachments
Screenshot4.png
Screenshot4.png (18.7 KiB) Viewed 3457 times
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Bad ID reference error

Post by Albert Wiersch »

Let's try 'tricking' CSS HTML Validator into thinking that id="CmtBox" has been used.

To do this, create a text file (like userfunctions.cfg) and copy and paste this into it:

Code: Select all

function onStartValidation() {
 $idattusedarraycase.insert('CmtBox');
 $idattusedarraynocase.insert('CmtBox');
 $idattusedarray[]='CmtBox';
}

function onMessageID_2017092000() {
 if strpos($omid_msgtext,'"CmtBox"')>=0 { $omid_cancel=true; }
}
Now go to the Validator Engine Options and the 'Config File' options page. Specify your new file (i.e. userfunctions.cfg) in the 'User functions' option. Next, reload the config (using the Reload Config button) or just restart CSS HTML Validator in order for the program to load and start using the new user functions file.

It will also disable/cancel any errors generated when/if id="CmtBox" is actually used (because it will think it has been used more than once).

Not the most elegant solution but I think it will work. Please let me know how it works for you.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
JimM77
Rank 0 - Newcomer
Posts: 8
Joined: Tue Nov 08, 2022 2:27 am

Re: Bad ID reference error

Post by JimM77 »

Yes, that worked fine, thanks so much. You are a marvel.

Maybe you might consider in a future release adding a message for cases of "not found in document" with specific references so that one could disable the message by exact text match?
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Bad ID reference error

Post by Albert Wiersch »

JimM77 wrote: Thu Nov 10, 2022 2:51 am Yes, that worked fine, thanks so much. You are a marvel.
Great! I'm glad it is working.
JimM77 wrote: Thu Nov 10, 2022 2:51 amMaybe you might consider in a future release adding a message for cases of "not found in document" with specific references so that one could disable the message by exact text match?
Yes, I'll have to think about this. The link checker works differently. I should probably find a way to make the link checker filters apply to ID reference issues as well. I will put this on my "to-do" list for future consideration.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Post Reply