Suggest WordPress plugin and no XHTML validation errors

A tip for the Suggest WordPress plugin which I mentioned in a previous post.

I had noticed that activating that plugin caused my blog to fail XHTML validation because the input field uses the non-standard HTML autocomplete attribute and because the InstallAC JavaScript call is registered to occur at “shutdown” – e.g.: after the end of the HTML document. My solution was to comment out this line in suggest.php:

      add_action('shutdown','insert_suggestLoad');

and then add the following to my template:

<body onload="main()">
<script type="text/javascript">
function setupSuggestions() {
  document.getElementById('s').setAttribute('autocomplete', 'off');
  InstallAC(document.searchform,
    document.searchform.s,
    document.searchform.subButton,
    "<?php echo $suggest_path; ?>suggest_data.php","en","","","",
    <?php echo """.$COLOR_MARKED_ROW."", "".$COLOR_RESULTS."", "".
    $COLOR_SUGGEST."", "".$TEXT_FONT.""";?>);
}
function main() {
 <?php if (isSet($suggest_path)) echo " setupSuggestions();"; ?>
}
</script>

This takes care of calling InstallAC if the plugin is activated and also sets the autocomplete attribute in a backhanded way that the HTML Validator won’t notice 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *