...

View Full Version : calling an external js file



j05hr
12-28-2008, 03:15 PM
Not sure if this is the right place to put this but wasn't sure where else to put it.

I've got a contact form that has javascript in it, if I have the javascript in the header it works fine, if I load it in an external file and link the php page to it, it doesn't load, I don't know anything about javascript and the only way I can tell if it loads is if the javascript calender works.

I'm not sure if i'm putting the <script type="text/javascript" src="contact.js"></script> in the right place?

The php page can be viewed at www.jasongold.org/contact1.php

I had to take the javascript out as it was too long to post but you can view the javascript can be viewd at www.jasongold.org/contact.js

I also had to take out the bottom of the php page as it was still too long (I don't think the bottom will have anything to do with it?)

the php code:


<?php
include_once( "contact.config.php" );

$atsymbol = "@"; $safename = $emailname; $safedomain = $emaildomain;
$safeccname = $ccemailname; $safeccdomain = $ccemaildomain;
if (empty ($ccemailname)) { $ccemailat = ""; } else { $ccemailat = $atsymbol; }

define( "BUG_REPORT", "barrym@owt200x.us" );
define( "HOST_NAME", getEnv( "HTTP_HOST" ) );
define( "PHP_SELF", getEnv( "SCRIPT_NAME" ) );
define( "ERR_MISSING", "Missing Required Field:&nbsp;" );
define( "ERR_EMAIL", "Invalid&nbsp;" );
define( "ERR_SELECT_UPLOAD", "Please Select Upload File<br>" );

error_reporting( E_ERROR | E_WARNING | E_PARSE );

$form_mail[] = array( "name" => "Name", "text" => "Name", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "esh_formmail_subject", "text" => "Subject", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Email_Address", "text" => "Email Address", "type" => "sender's email", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Daytime_Telephone", "text" => "Daytime Telephone", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Evening_Telephone", "text" => "Evening Telephone", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Reach_Me_By", "text" => "Reach Me By", "type" => "select", "required" => "Required" ) ;
$form_mail[] = array( "name" => "How_I_Found_You", "text" => "How I Found You", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Type_of_Event", "text" => "Type of Event", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "Date_of_Event", "text" => "Date of Event", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "Budget", "text" => "Budget", "type" => "select", "required" => "" ) ;
$form_mail[] = array( "name" => "Comments_or_Questions", "text" => "Comments or Questions", "type" => "textarea", "required" => "" ) ;

$isHideForm = false;

if( $_POST["formmail_submit"])
{
$sErr = checkPass();
if( ! $sErr ){
sendFormMail( $form_mail, "") ;
$isHideForm = true;

$redirect = "";
if( strlen(trim($redirect)) ):
header( "Location:$redirect" );
exit;
endif;
}
}

function sendFormMail( $form_mail, $sFileName = "" )
{
global $_POST ;

$to = $_POST["esh_formmail_recipient"];
$from = "online.submit@" . HOST_NAME ;
$subject = $_POST["esh_formmail_subject"];
$sWhatToDo = $sFileName ? "mailandfile" : "" ;
$cc = $_POST["esh_formmail_cc"];
$bcc = $_POST["esh_formmail_bcc"];
$charset = $_POST["esh_formmail_charset"];

for( $i = 0; $i < count( $form_mail ); $i ++ ){
$value = trim( $_POST[ $form_mail[ $i ][ "name" ] ] );
$content .= $form_mail[ $i ][ "text" ] . " \t : " . $value ."\n";
$line .= remove_newline( $value ) . "\t" ;
if( strtolower("Sender's email") == strtolower($form_mail[ $i ][ "type" ]) ) {

$from = $value ;
}
};
$content .= "\n\nIP:" . getEnv( "REMOTE_ADDR" );

switch( strtolower($sWhatToDo) ){
case "mailandfile" :
mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
if( ! appendToFile( $sFileName, $line ) )
mailReport( $content . "\n\nWrite Form Mail to File Fail." );
break;

case "fileonly" :
if( ! appendToFile( $sFileName, $line ) )
mailReport( $content . "\n\nWrite Form Mail to File Fail.", $from );
break;

default :
mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
}

mailAutoResponse( $from ) ;
}

function mailAutoResponse( $to ){
global $_POST ;
$subject = $_POST["esh_formmail_return_subject"];
$responseMsg = $_POST["esh_formmail_return_msg"];
if( $to && $responseMsg )
mail( $to, $subject, $responseMsg, "From: " . $_POST["esh_formmail_recipient"] );
}

function mailReport( $content = "", $from = "" ){
mail( BUG_REPORT, "Error@" . HOST_NAME . PHP_SELF, $content, "From:$from" );
}

function remove_newline( $str = "" ){
$newliner = "<!--esh_newline-->" ;
$newtaber = "<!--esh_newtaber-->" ;
$str = ereg_replace( "\t", $newtaber, $str );
$str = ereg_replace( "\r\n", $newliner, $str );
return ereg_replace( "\n", $newliner, $str );
}

function checkPass()
{
global $form_mail ;
global $_POST ;
global $HTTP_POST_FILES ;

for( $i = 0; $i < count( $form_mail ); $i ++ ){
$type = strtolower( $form_mail[ $i ][ "type" ] );
$value = trim( $_POST[ $form_mail[ $i ][ "name" ] ] );
$required = $form_mail[ $i ][ "required" ] ;
$text = stripslashes( $form_mail[ $i ][ "text" ] );

if( !strlen($value) && ( $required == "Required" ) && $type != "attachment" )
return ERR_MISSING . $text ;

if(
( strlen($value) || $type == "attachment" )
&& $required == "Required"
):
switch( $type ){
case strtolower("Sender's Name") :
break;
case strtolower("Generic email"):
case strtolower("Sender's email"):
if( ! formIsEMail($value) ) return ERR_EMAIL . $text ;
break;
case "text" :
break;
case "textarea" :
break;
case "checkbox" :
case "radio" :
break;
case "select" :
break;
case "attachment" :
$upload_file = $HTTP_POST_FILES[ $form_mail[ $i ]["name"] ][ "tmp_name" ] ;
if( ! is_uploaded_file($upload_file) )
return ERR_SELECT_UPLOAD . $text;
break;
case strtolower("Time(HH:MM:SS)"):
break;
case strtolower("Time(HH:MM)"):
break;
default :

}
endif;
}

return "" ;
}

function formSelected( $var, $val )
{
echo ( $var == $val ) ? "selected" : "";
}

function formChecked( $var, $val )
{
echo ( $var == $val ) ? "checked" : "";
}

function formIsEMail( $email ){
return ereg( "^(.+)@(.+)\\.(.+)$", $email );
}

function selectList( $name, $selectedValue, $start, $end, $prompt = "-Select-", $style = "" )
{
$tab = "\t" ;
print "<select name=\"$name\" $style>\n" ;
print $tab . "<option value=''>$prompt</option>\n" ;
$nLen = strlen( "$end" ) ;
$prefix_zero = str_repeat( "0", $nLen );
for( $i = $start; $i <= $end ; $i ++ ){
$stri = substr( $prefix_zero . $i, strlen($prefix_zero . $i)-$nLen, $nLen );
$selected = ( $stri == $selectedValue ) ? " selected " : "" ;
print $tab . "<option value=\"$stri\" $selected >$stri</option>\n" ;
}
print "</select>\n\n" ;
}

function mailAttachments( $to = "" , $subject = "" , $message = "" , $from = "barrym@owt200x.us" , $charset = "iso-8859-1", $cc = "" , $bcc = "" ){
global $HTTP_POST_FILES ;

if( ! strlen( trim( $to ) ) ) return "Missing \"To\" Field." ;

$boundary = "====_OwT_PHP_Contact_Form_" . md5( uniqid( srand( time() ) ) ) . "====";

$headers = "From: $from\r\n";
if ($cc) $headers .= "CC: $cc\r\n";
if ($bcc) $headers .= "BCC: $bcc\r\n";
$plainHeaders = $headers ;
$headers .= "MIME-Version: 1.0\nContent-type: multipart/mixed;\n\tboundary=\"$boundary\"\n";

$txtMsg = "\nThis is a multi-part message in MIME format.\n" .
"\n--$boundary\n" .
"Content-Type: text/plain;\n\tcharset=\"$charset\"\n\n" . $message . "\n";

$sError = "" ;
$nFound = 0;
foreach( $HTTP_POST_FILES as $aFile ){
$sFileName = $aFile[ "tmp_name" ] ;
$sFileRealName = $aFile[ "name" ] ;
if( is_file( $sFileName ) ):

if( $fp = fopen( $sFileName, "rb" ) ) :
$sContent = fread( $fp, filesize( $sFileName ) );
$sFName = basename( $sFileRealName ) ;
$sMIME = getMIMEType( $sFName ) ;

$bPlainText = ( $sMIME == "text/plain" ) ;
if( $bPlainText ) :
$encoding = "" ;
else:
$encoding = "Content-Transfer-Encoding: base64\n";
$sContent = chunk_split( base64_encode( $sContent ) );
endif;

$sEncodeBody .= "\n--$boundary\n" .
"Content-Type: $sMIME;\n" .
"\tname=\"$sFName\"\n" .
$encoding .
"Content-Disposition: attachment;\n" .
"\tfilename=\"$sFName\"\n\n" .
$sContent . "\n" ;
$nFound ++;
else:
$sError .= "<br>File $sFileName can not open.\n" ;
endif;

else:
$sError .= "<br>File $sFileName doesn't exist.\n" ;
endif;
};

$sEncodeBody .= "\n\n--$boundary--" ;
$sSource = $txtMsg . $sEncodeBody ;


$nFound ? mail( $to, $subject, $sSource, $headers )
: mail( $to, $subject, $message, $plainHeaders );

return $sError ;
}

function getMIMEType( $sFileName = "" ) {

$sFileName = strtolower( trim( $sFileName ) );
if( ! strlen( $sFileName ) ) return "";

$aMimeType = array(
"txt" => "text/plain" ,
"pdf" => "application/pdf" ,
"zip" => "application/x-compressed" ,

"html" => "text/html" ,
"htm" => "text/html" ,

"avi" => "video/avi" ,
"mpg" => "video/mpeg " ,
"wav" => "audio/wav" ,

"jpg" => "image/jpeg " ,
"gif" => "image/gif" ,
"tif" => "image/tiff " ,
"png" => "image/x-png" ,
"bmp" => "image/bmp"
);
$aFile = split( "\.", basename( $sFileName ) ) ;
$nDiminson = count( $aFile ) ;
$sExt = $aFile[ $nDiminson - 1 ] ;

return ( $nDiminson > 1 ) ? $aMimeType[ $sExt ] : "";
}

function appendToFile( $sFileName = "", $line = "" ){
if( !$sFileName || !$line ) return 0;
$hFile = fopen( "$sFileName", "a+w" );
$nBytes = 0;
if( $hFile ){
$nBytes = fputs( $hFile , trim($line)."\r\n" );
fclose( $hFile );
};
return $nBytes ;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<link rel="stylesheet" type="text/css"
href="css4.css" >
<link rel="stylesheet" type="text/css"
href="contact.css" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<title>Contact</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" >
<style type="text/css">
<!--
.style30 {color: #FFFFFF}
-->
</style>

<script type="text/javascript" src="contact.js"></script>
</head>

<body id="contact">
<div class="header"></div>
<div class="logo"><img src="logo.jpg" width="200" height="100" /></div>
<div class="bar1"><img src="header.jpg" width="799" height="100" align="absbottom" /></div>
<span class="style1 style22"><span class="style6"><strong>
<div class="left_column">
<div align="center">
<div id="menu">
<ul id="navlist">
<li><a href="index.html" title="Link to Homepage">Home</a>
<ul>
<li><a href="about.html" title="Link to About Page" >About</a></li>
<li><a href="portfolio.html" title="Link to Portfolio Page">Portfolio</a>
<ul>
<li><a href="fashion.html" title="Link to Fashion Page">Fashion</a></li>
<li><a href="portrait.html" title="Link to Portrait Page">Portrait</a></li>
<li><a href="reportage.html" title="Link to Reoportage Page">Reportage</a></li>
<li><a href="travel.html" title="Link to Travel Page" >Travel</a></li>
</ul>
</li>
<li><a href="contact1.html" title="Link to contact page" id="connav">Contact</a></li>
</ul>
</li>
</ul>

</div>

</div>
</div>

<div class="about">

<legend>Contact Details</legend>

<form onClick="highlight(event)" name="<?php echo $formname; ?>" action="<?php print PHP_SELF ?>" method='post' enctype='multipart/form-data'>
<input type='hidden' name='formmail_submit' value='Y'>
<input type='hidden' name='esh_formmail_recipient' value="<?php echo $safename; echo $atsymbol; echo $safedomain; ?>">
<input type='hidden' name='esh_formmail_cc' value="<?php echo $safeccname; echo $ccemailat; echo $safeccdomain; ?>">
<input type='hidden' name='esh_formmail_return_subject' value="<?php echo $autorespondsubject; ?>">
<input type='hidden' name='esh_formmail_return_msg' value="<?php echo $autorespondmessage; ?>">
<input type='hidden' name='esh_formmail_charset' value="">
<center><img src="required.gif" width="12" height="12">&nbsp;<font color="#FFFFFF">Denotes Required Field<br><noscript>For best form performance, please enable Javascript.</noscript><br></font></center>

<?php
if( !$isHideForm ):
global $sErr ;
if( $sErr ) print "<a name='error'></a><center><font class='form_error' >$sErr</font></center>";

$starColor = $sErr ? "#ff0000" : "#000000";
$style=" class='form_text' ";

?>
<li>
<label for="name" class="style30">Name:&nbsp;<img src="required.gif" width="12" height="12"></label>
<input name="Name" onBlur="stripHTML(<?php echo $formname; ?>.Name)" type="text" size="25" maxlength="30" value="<?php print HtmlSpecialChars( $_POST[ "Name" ] ); ?>"/>
</li>
<li>
<label for="subject" class="style30">Subject:&nbsp;<img src="required.gif" width="12" height="12"></label>
<input name="esh_formmail_subject" onBlur="stripHTML(<?php echo $formname; ?>.esh_formmail_subject)" type="text" size="25" maxlength="30" value="<?php print HtmlSpecialChars( $_POST[ "esh_formmail_subject" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Email Address:&nbsp;<img src="required.gif" width="12" height="12"></label>
<input name="Email_Address" onBlur="stripHTML(<?php echo $formname; ?>.Email_Address)" type="text" size="25" maxlength="50" value="<?php print HtmlSpecialChars( $_POST[ "Email_Address" ] ); ?>" />
</li>
<li>
<label for="phone" class="style30">Daytime Phone Number:&nbsp;<img src="required.gif" width="12" height="12"></label>
<input name="Daytime_Telephone" onBlur="stripHTML(<?php echo $formname; ?>.Daytime_Telephone)" type="text" size="25" maxlength="12" value="<?php print HtmlSpecialChars( $_POST[ "Daytime_Telephone" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Evening Phone Number:&nbsp;<img src="required.gif" width="12" height="12"></label>
<input name="Evening_Telephone" onBlur="stripHTML(<?php echo $formname; ?>.Evening_Telephone)" type="text" size="25" maxlength="12" value="<?php print HtmlSpecialChars( $_POST[ "Evening_Telephone" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Best way to reach you:&nbsp;<img src="required.gif" width="12" height="12"></label>
<select name="Reach_Me_By">
<option value="Email" selected="Selected" <?php formSelected( $_POST[ "Reach_Me_By" ], "Email" ); ?>>E-mail</option>
<option value="Daytime Telephone" <?php formSelected( $_POST[ "Reach_Me_By" ], "Daytime Telephone" ); ?>>Daytime Telephone</option>
<option value="Evening Telephone" <?php formSelected( $_POST[ "Reach_Me_By" ], "Evening Telephone" ); ?>>Evening Telephone</option>
</select>
</li>
<li>
<label for="email"><span class="style30">How did you find me:&nbsp;<img src="required.gif" width="12" height="12"></span></label>
<input name="How_I_Found_You" onBlur="stripHTML(<?php echo $formname; ?>.How_I_Found_You)" type="text" size="25" maxlength="50" value="<?php print HtmlSpecialChars( $_POST[ "How_I_Found_You" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Type of event:</label>
<input name="Type_of_Event" onBlur="stripHTML(<?php echo $formname; ?>.Type_of_Event)" type="text" size="25" maxlength="30" value="<?php print HtmlSpecialChars( $_POST[ "Type_of_Event" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Date of event:</label>
<input name="Date_of_Event" OnClick="javascript:showCal('Calendar')" onBlur="stripHTML(<?php echo $formname; ?>.Date_of_Event)" type="text" size="25" maxlength="20" value="<?php print HtmlSpecialChars( $_POST[ "Date_of_Event" ] ); ?>" />
</li>
<li>
<label for="email" class="style30">Budget:</label>
<select name="Budget">
<option value="100 - 300" selected="Selected" <?php formSelected( $_POST[ "Budget" ], "100 - 300" ); ?>>100 - 300</option>
<option value="300 - 500" <?php formSelected( $_POST[ "Budget" ], "300 - 500" ); ?>>300 - 500</option>
<option value="500 - 700" <?php formSelected( $_POST[ "Budget" ], "500 - 700" ); ?>>500 - 700</option>
<option value="700 - 900" <?php formSelected( $_POST[ "Budget" ], "700 - 900" ); ?>>700 - 900</option>
<option value="900 - 1100" <?php formSelected( $_POST[ "Budget" ], "900 - 1100" ); ?>>900 - 1100</option>
<option value="1100+" <?php formSelected( $_POST[ "Budget" ], "1100+" ); ?>>1100+</option>
</select>
</li>
<li>
<label for="email"><span class="style30">Comments or Questions:</span>ns:</label>
<textarea name="Comments_or_Questions" onBlur="stripHTML(<?php echo $formname; ?>.Comments_or_Questions)" cols="25" rows="3"><?php print HtmlSpecialChars( $_POST[ "Comments_or_Questions" ] ); ?></textarea>
</li>
<li>

<div align="center">

<input type="submit" name="Submit" value="Submit" />
</div>
</li>
</fieldset>
</form>
<?php

if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;;

else:
print( "<br><br><center><b>$thankyoumessage</b></center>" );
endif;


?>

Philip M
01-07-2009, 01:24 PM
Have you removed the HTML tags
<script type = "text/javascript">
and
</script>
from the external file?


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum