Adding a small javascript file to functions.php

I want to use Hostgator’s javascript validator to validate simple forms using WordPress. This is the code I’ve put in the functions.php of a genesis child theme.

function hgformcode() {

echo ‘<script type=”text/javascript” src=”hgformcode.js”></script>’;


add_action(‘wp_head’, ‘hgformcode’:wink:;

I put the Hostgator javascript file in the child theme folder. I called it hgformcode.js

This is the Hostgator javascript validator.

function hgsubmit()


if (/S+/.test( == false) alert (“Please provide your name.”:wink:;

else if (/^S+@[a-z0-9_.-]+.[a-z]{2,6}$/i.test( == false) alert (“A valid email address is required.”:wink:;

else if (/S+/.test(document.hgmailer.comment.value) == false) alert (“Your email content is needed.”:wink:;

else {


alert (‘Thank you!nYour email is sent.’:wink:;



I’m doing this to avoid maintenance by not using a form plugin. I only want one form on the site.

This works but is it safe?

Thanks for your help