This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Tuesday, January 10, 2012

Server Migration Under Way

We are currently in the process of migrating over to the new server for website and e-mail hosting.  So far the project has been going along fantastically.  We need to get all sites moved as soon as possible do to a temporary hosting license.  If DNSTC does not maintain your domain registration, we will be in contact with you for the new server's settings.

Monday, January 2, 2012

Formatting MySQL datetime field in PHP

If you would like to get a nice format on the datetime field stored in MySQL, use the following code:

<?php

    $datetime = strtotime($row_links['dateAdded']); // The date time field
    $formatDate = date("m/d/y g:i A", $datetime);
    echo $formatDate;

?>

This will output something like:

01/01/12 8:07 PM

If you want more formatting options for the date(), you can review the manual on PHP.net here.

Form Validation with JS

imageOne of the important elements in form design is the implementation of form validation.  This helps to ensure that the data being submitted is cleaned and that the user enters the required information that you want for the form.  If you do not include any type of validation on your form, then it is possible to get corrupt data or open your form for possible hacking attempts.

To create a great form validation system, there are four steps to implementation:

  1. Make sure each of your fields have an id attribute.
  2. Include the validation functions within the heading of your page.
  3. Create a unique validation function for your form.
  4. Add the validation code to the onSubmit attribute of the form.

Validation Functions

We have created several functions that can be used to help with the validation of a form.  These functions will check to see if the field is empty, check to see if the field is numeric, check to see if the field is alpha numeric, check the length of the field, check to see if an item has been selected, and check to see if a valid e-mail address has been entered.

Add the following functions within a javascript section within the heading:

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}

function madeSelection(elem, helperMsg){
if(elem.value == "Please Select"){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}

function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

Unique Validation Function for the Form


You will not have to look at each of the fields that you want to validate, and create a function that is called when the form is submitted.  The following is an example of how this will work.

function validateForm() {

var valid = false;

var subcat = document.getElementById('subcat');
var name = document.getElementById('Name');
var email = document.getElementById('email');
var linkText = document.getElementById('linkText');
var linkURL = document getElementById('linkURL');
var siteDescription = document.getElementById('siteDescription');
var reciprocalPage = document.getElementById('reciprocalPage');

if(notEmpty(subcat, "You need to select a category.")){
if(notEmpty(name, "You need to provide your name.")){
if(emailValidator(email, "You need to provide your e-mail.")){
if(notEmpty(linkText, "You need to provide a title for your link.")){
if(notEmpty(linkURL, "You need to provide a URL for your link.")){
if(notEmpty(siteDescription, "You need to provide a description for your site.")){
if(notEmpty(reciprocalPage, "You need to provide the URL to the page you placed our link.")){
valid=true;
}
}
}
}
}
}
}

return valid;

}

Explanation:


Here is the flow as to how this function works…



  1. The variable valid is set to false.
  2. The value of the fields you want to validate are assigned to variables.
  3. The nested condition statement goes through each variable and validates the fields calling the appropriate functions.
  4. The function then returns the valid status back to the form.  If the status is true, it is submitted.  If the status is false, then a window pops up and tells the user what they need to correct in order to submit the form.

Adding the validation function to your form


The last thing you have to do is add the validation call to a “OnSubmit” attribute of your form.

<form action="post.php" 
name="myform"
method="post"
onsubmit="return validateForm();">

Now when the submit button is clicked, the validation system should check the fields you want validated.

Wednesday, December 14, 2011

Choosing your Site Colors

If you have every got stumped on coming up with a color scheme for a website, try the Color Hunter website at http://www.colorhunter.com/.

With this website, you can upload an image, and the site will generate an odd number of colors (five) that can be used as the color palette for your web design and layout.

This is a great site too to give to clients to help them determine what they are looking for with the design. We sometimes save these swatches and e-mail them to the client as well.

This site has been added to our Utilities and resources page too. GREAT TOOL!

Should I Use Facebook as My Website?


I have debated this topic with many business owners in the past; however, according to the terms of use with Facebook, here is the proper way to get your business on Facebook.


Thursday, December 8, 2011

Add Google +1 to Your Website






We will have more information on this at a later date (as to why you want to add this to your site if you have social networking links), but for now, we would like to just provide the page that will help you setup your Google +1 button.


The page is: http://www.google.com/webmasters/+1/button/index.html

Once you add this to your site, your visitors can then click on the Google +1 icon to share the information within Google + (and within the search results for your page).
Again, as mentioned before, we will have more information on this later.

Wednesday, December 7, 2011

10 Tips Every Website Owner Should Know

This helpful article lays out 10 tips that every owner of every website should know to encourage others to link to their site. Topics include being at the forefront of new topics, using the power of social media, and starting off strong. By utilizing these 10 tips, the traffic to your site should increase drastically.