PDA

View Full Version : Form required fields



Didier
12-19-2008, 11:06 AM
1) Script Title: Required field(s) validation v1.10- By NavSurf

2) Script URL (on DD): http://navsurf.com/dhtml/formcheck/?viewcode=true


contact2.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript">
<!--
/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("Naam", "Email");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Naam", "Email");
// dialog message
var alertMsg = "Sorry, next fields are required:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mefaco - contactformulier</title>
<script type="text/javascript" src="simpletreemenu.js">

/***********************************************
* Simple Tree Menu- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<link rel="stylesheet" type="text/css" href="simpletree.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th class="style2" scope="row">&nbsp;</th>
<td width="950" background="bg.jpg" class="style2"><p><!--url's used in the movie-->
<!--text used in the movie-->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="950" height="335" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="topen.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#3e3e3e" />
<embed src="topen.swf" quality="high" bgcolor="#ffffff" width="950" height="335" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object><script type="text/javascript" src="ieupdate.js"></script></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th width="4" scope="row">&nbsp;</th>
<td width="276">
</td>
<td width="10">&nbsp;</td>
<td width="665">
<?php

require "connect.php";
$pand_db = db_connect();

$requete = "SELECT * FROM inhoud WHERE ID = 56";

$result = mysql_query ($requete,$pand_db) or pand_mysql_die();
$panden = mysql_fetch_object($result);

?>
<table width="94%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><? echo (html_entity_decode($panden->Engels)); ?><br /></td>
</tr>
</table></td>
</body>
</html>


And the contact2.php :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mefaco - contactformulier</title>
<script type="text/javascript" src="simpletreemenu.js">

/***********************************************
* Simple Tree Menu- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<link rel="stylesheet" type="text/css" href="simpletree.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th class="style2" scope="row">&nbsp;</th>
<td width="950" background="bg.jpg" class="style2"><p><!--url's used in the movie-->
<!--text used in the movie-->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="950" height="335" id="top" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="top.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#3e3e3e" />
<embed src="top.swf" quality="high" bgcolor="#ffffff" width="950" height="335" name="top" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object><script type="text/javascript" src="ieupdate.js"></script></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th width="4" scope="row">&nbsp;</th>
<td width="276">
</td>
<td width="10">&nbsp;</td>
<td width="665">

<table width="94%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<?
$message = "Deze items werden aangevinkt:<BR><BR>";

foreach($_POST as $veld => $waarde){

if ($veld == "Naam") {
$message = $message ."<BR><BR>Dit zijn de contactgegevens:<BR><BR>";
}
if ($veld <> "submit" && $veld <> "reset") {
$message = $message .$veld.": ".$waarde."<br />";
}
if ($veld == "Email") {
$email = $waarde;
}
}


// Hier worden de headers aangemaakt
$extra = "MIME-Version: 1.0\n";
$extra .= "From: ".$email."\n";
$extra .= "Content-type: text/html; charset=iso-8859-1\n";
$extra .= "To: didier@freez.be \n";

mail("", "Contactformulier op mefaco.be - nederlands", $message, $extra);

?>
<BR /><br />
Bedankt voor uw reactie.<br />
We zullen u zo spoedig mogelijk contacteren.<br />
<br />
<br />
Vriendelijke groeten,
<br />
MeFaCo bvba </td>
</tr>
</table></td>
</body>
</html>

This is a part of the contact form :

<form onsubmit="return formCheck(this);" action="contact2.php" method="post" width="550" border="0" bordercolorlight="#ffffff" align="center" cellpadding="5" bordercolordark="#000088" cellspacing="5" height="610" name="formcheck">
<p><strong>Bevestigingsmaterialen in kunststof</strong> <br /><input type="checkbox" name="Inserts voor plastics" value="on" />Kunststof inserts voor plastics (Amtec) <br /><input type="checkbox" name="Fasteners met kunststof kop" value="on" />Fasteners met kunststof kop <br /><input type="checkbox" name="Zelfsnijdende schroeven voor kunststoffen" value="on" />Zelfsnijdende schroeven voor kunststoffen

<tbody>
<tr>
<td><strong>Naam:</strong></td>
<td><input size="30" name="Naam" /></td>
</tr>
<tr>
<td><strong>Straat:</strong></td>
<td><input size="30" name="Straat" /></td>
</tr>
<tr>
<td><strong>Postnr./Stad:</strong></td>
<td><input size="30" name="Stad" /></td>
</tr>
<tr>
<td><strong>Telefoon:</strong></td>
<td><input size="10" name="Telefoon" /></td>
</tr>
<tr>
<td><strong>Fax:</strong></td>
<td><input size="10" name="Fax" /></td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td><input size="10" name="Email" /></td>
</tr>
</tbody>
</table>
</p>
<p align="center"><button name="submit" type="submit" value="Verzenden">Verzenden</button><button name="reset" type="reset" value="Opnieuw beginnen">Opnieuw beginnen</button></p>
</form>

3) Describe problem:
Hi, our website uses an contact form in 4 diff. languages and i want to use some required fields in those forms. We have for the lang. 2 php files contact.php and contact2.php, and using FCKeditor to make the layout that is stored in the database.
I have tryed to use it this way
But i cant get it to work, it always send the mail even no field is filled.
What could be wrong here, or is there a script that writes it to the database...

Thanks in advance,

Didier