Can I have user-defined error messages?


<< Can I pass user-defined p ...
Back to Portfolio FAQ index
Do PortWeb queries allow ... >>

There is no built-in method for taking care of the generic "There were no records matching your query" condition, which occurs when there are 0 results returned (the Catalogue and template are genuinely in this condition, so it's not really an error). This covers both the visual formatting of the error code and/or it addition/replacement with alternative text.

It is more difficult to address the serious errors, which are only returned with a string (not even body tags) without some hidden targets to manipulate. However with a little fudging around and a bit of JavaScript, you can manipulate the "no results found" type of string.

There is an easy way of totally eliminating this return string, but it does depend upon the PortWeb template putting an HTML comment string in the right place. (Explained in more detail below)

You can also make the template output look a little prettier without too much programming! The main PortWeb variable to be manipulated is the %page%, which is "fairly well" documented (manual p.282, 287). The item block is not interpreted when no results are found, but the header and footer blocks are returned. You can use the macros, for instance, to only show forms controls when there are results:

<!--Port4-%totalitems%-->
*** Put your forms controls here ***
<!--/Port4-%totalitems%-->

If the above doesn't make sense read the manual pp.286-7 on 'Macro Blocks' and 'Special Macro blocks'.

You can extend the above notion into JavaScript by using %totalitems% in a conditional macro block to format the 'error' string and perhaps put out other information, for example, if you want a font change and further explanation you can do something like:

[some lines starting with writeIn calls may wrap but are one code line]

----- in the header, after the <table> -----
<script>
if (%totalitems% == 0) {
document.title='Error Encountered';
document.write('<tr><td>');
document.write('<font face='Arial' size='2'>');
document.write('PortWeb has returned the following error:');
document.write('<br><font color='red'>');
}
</script>

----- in the footer, before the end of </table> -----
<script>
if (%totalitems% == 0) {
document.write('</font>');
document.write('<br>Please refer to the library's on line <a href="help.htm>help</a>');
document.write(' for further information.');
document.write('</font>');
document.write('</td></tr>');
}
</script>

----------------------------------------

...or the same with CSS styles, 'rederror' for your custom text and 'blackerror' for the PortWeb error text...

----- in the header, after the <table> -----
<script>
var myTotal = parseInt(%totalitems%);
if (myTotal == 0) {
document.title='Error Encountered';
document.write('<tr><td class="rederror' +'">');
document.write('PortWeb has returned the following error:-')
document.write('<br /><br /><span class="blackerror' + '">');
}
</script>

----- in the footer, before the end of &lt;/table&gt; -----
<script>
var myTotal = parseInt(%totalitems%);
if (myTotal == 0) {
document.write('</span><br />If you believe your query should have returned some matches,<br />');
document.write('please refer this error to the library <a href="mailto:bill@ben.com">administrator</a> copying the <br />');
document.write('whole of the URL in the browser\'s address bar into the body of your email.');
document.write('</td></tr>');
}
</script>

----------------------------------------

The tags and text will be incorporated around the standard error text. Of course you can get very elaborate and produce all sorts of effect. You put the "tr" and "td" tags in as PortWeb does not do this on its own. PortWeb emits the standard error text along with a tag after it in place of the entire item block.

That's it! Go experiment...



Question: Can I have user-defined error messages? [FAQ00226.htm]
Last Update:- 01 June 2006


<< Can I pass user-defined p ...
Back to Portfolio FAQ index
Do PortWeb queries allow ... >>

Quick Search of PortfolioFAQ (word, words or phase): or try the Advanced Search

User-to-User Forums  |  Report error/typo/broken link  |  Request new topic  |  Ask a question

Site and articles © Mark Anderson 2001-2007 - Visit my home page


This FAQ is created and maintained using
Friday logo
Friday - The Automatic FAQ Maker