In PHP we are provided with an integrated logging system for outputting info, warnings, and errors. This is accomplished by use of the syslog function. This function outputs the specified message at the specified priority level to the default system logger. If you want to have it output the log message to a user defined log handler then you simply need to utilize the openlog and closelog functions before and after respectively before you log a message.

Example Log Statements

syslog(LOG_ERR, "message to be logged as an error");
openlog("AppLog", LOG_PERROR, LOG_LOCAL0);
 
// code
 
syslog(LOG_WARNING, "warning priority sample log message");
 
// code
 
closelog();

Resources

, , , , ,

Often as a User we don’t want to use our mouse or tab to the submit button to submit a form on a Web page, instead we may just want to press the enter key on our keyboard. This functionality can be easily completed by performing a bit of JavaScript, personally I find that utilizing JQuery makes the task even easier.

Enabling Enter Button to Submit a Form

To enable the enter button for a form we will create a javascript function that check when a key is pressed when an input element of the form is in focus. This function can then either submit the form or call another javascript function to validate the form.

  1. First lets we will start by defining our start-up function that will setup the appropriate keydown handlers on the input fields.
    $(document).ready( function() {
        // code from step 2
    }
  2. Second we will need to set the keydown handler for all input fields in our form including select and radio fields. JQuery provides a shortcut selector :input to select these elements.
    $('#formID :input').keydown(function(e) {
        // code from step 3
    }
  3. Now time to fill out the logic of the function called when the enter key is pressed. First we will want to verify that we have the event to do this we can check if e is null and get the window.event instead. To shorten this we can simply use the || operator.
    var event = e || window.event;

    Next we check if the key pressed was the enter button by use of the keyCode property.

    if( e.keyCode == 13) {
        // action here
    }
  4. The last step is simply put in the action logic whether it is calling a validation script:
    return validateForm();

    or submitting the form directly

    document.formName.submit();

Full Sample Script

$(document).ready( function() {
    $('#myForm :input').keydown(function(e) {
        var event = e || window.event;
        if (e.keyCode == 13) {
           return validateForm();
        }
    });
});

Resources

,

Often when working with Bash scripts we find that we want to add some options to the script by way of arguments or variables. Easily enough Bash command line arguments can be accessed by $1, $2, etc within the script where $1 is the first argument or variable and #2 is the second etc.

Example:

#!/usr/bin/env bash
 
echo the first argument is $1
echo second argument is $2
echo eleventh argument is $11
echo total number of arguments is $#

Resources:

, , ,

Java provides multiple Text Formatting classes to enable easy conversion of integers, decimals, floats, and etc into Strings. The DecimalFormat class enables the formatting of Floats and Decimals and can be used to easily display percentages and currency amounts.

Example:

Converting a Float into Dollars formatted String

import java.text.DecimalFormat;
...
float amount = 100453.23f;
DecimalFormat dollarFormat = new DecimalFormat( "$#,##0.0#" );
System.out.println( dollarFormat.format( amount ) );

Resources:

, , ,

On today’s websites it is good practice to utilize a contact form instead of a mailto link. However you will find the occasions when you find the need to add a contact reference that does not require a form. In this cases you will find that you may want to set a predefined subject or even some body text. Below is a quick overview of how you can set these elements of the email from the mailto link.

General Format

The mailto format is similar to a website url in that you define the recipients followed by query parameters containing additional properties. Below is a quick format example:

mailto:address1,address2?prop1=value1&prop2=value2

Properties

Recipients comma seperated list following mailto:
Copy To or CC Recipients cc=emailaddress
Blind Copy To or BCC Recipients bcc=emailaddress
Subject subject=text here
Body body=Email message