Solved

Validate email field with another field

Posted on 2008-09-29
11
404 Views
Last Modified: 2011-08-18
Hi,  I'm using TNG for my genealogy home page and suggest.php and tngsendmail.php for people to send me their questions or comments.  I'm trying to insert an additional field under Email to have people enter their email twice to make sure they enter it correctly.  I need this additional field (ex.: tng_email2) to be required and to validate against the first email field (tng_email) and if the two do not match an error is shown.

The code for the form page (suggest.php) is as below.  If you need the code for tngsendmail.php, I can append it too.


<?php
include("begin.php");
$tngconfig['maint'] = "";
if($cms['events']){include('cmsevents.php'); cms_contact();}
include($cms['tngpath'] . "genlib.php");
$textpart = "gedcom";
include($cms['tngpath'] . "getlang.php");
include($cms['tngpath'] . "$mylanguage/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
if($enttype)
	include($cms['tngpath'] . "checklogin.php");
else
	$currentuser = $_SESSION[currentuser];
 
$_SESSION['tng_email'] = generatePassword(1);
$_SESSION['tng_comments'] = generatePassword(1);
$_SESSION['tng_yourname'] = generatePassword(1);
 
$flags[scripting] = "<script type=\"text/javascript\">
function validateForm() {
	if( document.suggest." . $_SESSION['tng_yourname'] . ".value == \"\" ) {
		alert(\"$text[entername]\");
		return false;
	}
	if( document.suggest." . $_SESSION['tng_email'] . ".value.length == 0 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\".\") < 1 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\"@\") <= 0 ) {
		alert(\"$text[enteremail]\");
		return false;
	}
	if( document.suggest." . $_SESSION['tng_comments'] . ".value == \"\" ) {
		alert(\"$text[entercomments]\");
		return false;
	}
	return true;
}
</script>\n";
 
if( $enttype == "I" ) {
	$typestr = "person";
	$query = "SELECT firstname, lnprefix, lastname, prefix, suffix, sex, nameorder, living, branch, disallowgedcreate, IF(birthdatetr !='0000-00-00',YEAR(birthdatetr),YEAR(altbirthdatetr)) as birth, IF(deathdatetr !='0000-00-00',YEAR(deathdatetr),YEAR(burialdatetr)) as death 
		FROM $people_table, $trees_table WHERE personID = \"$ID\" AND $people_table.gedcom = \"$tree\" AND $people_table.gedcom = $trees_table.gedcom";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	if( $result ) {
		$row = mysql_fetch_assoc($result);
		$rightbranch = checkbranch( $row[branch] );
		$row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
		$disallowgedcreate = $row[disallowgedcreate];
		$name = getName( $row ) .  " ($ID)";
		mysql_free_result($result);
	}
 
	$years = getYears( $row );
}
elseif( $enttype == "F" ) {
	$typestr = "family";
	$query = "SELECT familyID, husband, wife, living, marrdate, gedcom, branch FROM $families_table WHERE familyID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	mysql_free_result($result);
 
	$rightbranch = checkbranch( $row[branch] ) ? 1 : 0;
	$row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
	$name = "$text[family]: " . getFamilyName( $row );
	
	$years = "";
}
elseif( $enttype == "S" ) {
	$query = "SELECT title FROM $sources_table WHERE sourceID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	mysql_free_result($result);
	
	$query = "SELECT count(personID) as ccount FROM $citations_table, $people_table 
		WHERE $citations_table.sourceID = '$ID' AND $citations_table.persfamID = $people_table.personID AND $citations_table.gedcom = $people_table.gedcom
		AND living = '1'";
	$sresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$srow = mysql_fetch_assoc( $sresult );
	$row[living] = $srow[ccount] ? 1 : 0;
	
	if( !$row[living] || $livedefault == 2 || ( !$livedefault && $allow_living_db && ( !$assignedtree || $assignedtree == $row[gedcom] ) ) )
		$row[allow_living] = 1;
	else
		$row[allow_living] = 0;
	mysql_free_result( $sresult );
	
	$name = "$text[source]: $row[title] ($ID)";
	$years = "";
}
elseif( $enttype == "R" ) {
	$query = "SELECT reponame FROM $repositories_table WHERE repoID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	mysql_free_result($result);
	
	$row[living] = 0;
	$row[allow_living] = 1;
	
	$name = "$text[repository]: $row[reponame] ($ID)";
}
if( $enttype ) {
	$flags[tabs] = $tngconfig[tabs];
	$headline = "$text[suggestchange]: $name";
	$comments = $text[comments];
	tng_header( $headline, $flags );
	
	$photostr = showSmallPhoto( $ID, $name, $row[allow_living], 0 );
	echo tng_DrawHeading( $photostr, $name, $years );
	echo tng_coreicons();
	$innermenu = "&nbsp; \n";
	echo tng_menu( $enttype, "suggest", $ID, $innermenu );
	$buttontext = $text[submitsugg];
}
else {
	$headline = $text[contactus];
	$comments = $text[comments2];
	tng_header( $headline, $flags );
?>
 
<p class="header"><img src="<?php echo $cms[tngpath]; ?>tng_contact.gif" width="20" height="20" alt="" style="vertical-align:-2px" />&nbsp;<?php echo $headline; ?></p><br clear="left"/>
<?php
	echo tng_coreicons();
	$buttontext = $text['sendmsg'];
}
 
if( $message ) {
	$newmessage = $text[$message];
	if( $message == "mailnotsent" ) {
		$newmessage = ereg_replace( "xxx", $sowner, $newmessage );
		$newmessage = ereg_replace( "yyy", $ssendemail, $newmessage );
	}
	echo "<p class=\"normal\"><strong><font color=\"red\">$newmessage</font></strong></p>\n";
}
 
if( $enttype )
	echo "<span class=\"subhead\"><b>$headline</b></span><br /><br />\n";
?>
 
<?php
@include($cms['tngpath'] . "TNG_captcha.php");
 
$formstr = getFORM( "tngsendmail", "post\" onsubmit=\"return validateForm();", "suggest", "suggest" );
echo $formstr;
?>
<input type="hidden" name="<?php echo $typestr; ?>ID" value="<?php echo $ID; ?>" />
<input type="hidden" name="tree" value="<?php echo $tree; ?>" />
<br>
<table border="0" cellspacing="1" cellpadding="4" width="80%">
  <tr><td class="fieldnameback" width="20%"><span class="fieldname"><?php echo $text[yourname]; ?>:&nbsp; </span></td><td class="databack" width="80%"><input type="text" name="<?php echo $_SESSION['tng_yourname']; ?>" /></td></tr>
<tr><td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:&nbsp; </span></td><td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email']; ?>" /> &nbsp; <input type="checkbox" name="mailme" value="1" /><?php echo $text[mailme]; ?></span></td></tr>
<tr>
	<td class="fieldnameback" valign="top"><span class="fieldname"><?php echo $comments; ?>:&nbsp; </span></td>
	<td class="databack">
		<textarea cols="60" rows="10" name="<?php echo $_SESSION['tng_comments']; ?>"></textarea>
	</td>
</tr>
<tr><td>&nbsp;</td><td><span class="normal"><input type="submit" value="<?php echo $buttontext; ?>" /></span></td></tr>
</table>
<p> 
  <input type="hidden" name="enttype" value="<?php echo $enttype; ?>" />
  <input type="hidden" name="ID" value="<?php echo $ID; ?>" />
  <input type="hidden" name="tree" value="<?php echo $tree; ?>" /></form> 
  <br />
  <br />
  <b><?php echo $text[address3]; ?></b></p>
<p> <u><?php echo $text[address]; ?> :</u><br>
  <?php echo $text[address1]; ?></p>
<p><u><?php echo $text[address2]; ?></u><br>
  <a href="mailto:l_chance@hotmail.com">l_chance@hotmail.com</a><br>
  <a href="mailto:info@lachancefamily.com">info@lachancefamily.com</a><br>
  <a href="mailto:rila@ntl.sympatico.ca">rila@ntl.sympatico.ca</a><br />
  <br />
  <?php
	tng_footer( "" );
?>
</p>

Open in new window

0
Comment
Question by:theresel
  • 7
  • 4
11 Comments
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22599852
The function to validate will be:
function validateForm() {
        if( document.suggest." . $_SESSION['tng_yourname'] . ".value == \"\" ) {
                alert(\"$text[entername]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_email'] . ".value.length == 0 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\".\") < 1 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\"@\") <= 0 ) {
                alert(\"$text[enteremail]\");
                return false;
        }
        if(document.suggest." . $_SESSION['tng_email'] . ".value != document.suggest." . $_SESSION['tng_email2'] . ".value)
        {
                alert(\"$text[enteremail]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_comments'] . ".value == \"\" ) {
                alert(\"$text[entercomments]\");
                return false;
        }
        return true;
}
</script>\n";

Open in new window

0
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22599916
<?php
include("begin.php");
$tngconfig['maint'] = "";
if($cms['events']){include('cmsevents.php'); cms_contact();}
include($cms['tngpath'] . "genlib.php");
$textpart = "gedcom";
include($cms['tngpath'] . "getlang.php");
include($cms['tngpath'] . "$mylanguage/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
if($enttype)
        include($cms['tngpath'] . "checklogin.php");
else
        $currentuser = $_SESSION[currentuser];
 
$_SESSION['tng_email'] = generatePassword(1);
$_SESSION['tng_comments'] = generatePassword(1);
$_SESSION['tng_yourname'] = generatePassword(1);
 
$flags[scripting] = "<script type=\"text/javascript\">
function validateForm() {
        if( document.suggest." . $_SESSION['tng_yourname'] . ".value == \"\" ) {
                alert(\"$text[entername]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_email'] . ".value.length == 0 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\".\") < 1 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\"@\") <= 0 ) {
                alert(\"$text[enteremail]\");
                return false;
        }
        if(document.suggest." . $_SESSION['tng_email'] . ".value != document.suggest." . $_SESSION['tng_email2'] . ".value)
        {
                alert(\"$text[enteremail]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_comments'] . ".value == \"\" ) {
                alert(\"$text[entercomments]\");
                return false;
        }
        return true;
}
</script>\n";
 
if( $enttype == "I" ) {
        $typestr = "person";
        $query = "SELECT firstname, lnprefix, lastname, prefix, suffix, sex, nameorder, living, branch, disallowgedcreate, IF(birthdatetr !='0000-00-00',YEAR(birthdatetr),YEAR(altbirthdatetr)) as birth, IF(deathdatetr !='0000-00-00',YEAR(deathdatetr),YEAR(burialdatetr)) as death
                FROM $people_table, $trees_table WHERE personID = \"$ID\" AND $people_table.gedcom = \"$tree\" AND $people_table.gedcom = $trees_table.gedcom";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        if( $result ) {
                $row = mysql_fetch_assoc($result);
                $rightbranch = checkbranch( $row[branch] );
                $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
                $disallowgedcreate = $row[disallowgedcreate];
                $name = getName( $row ) .  " ($ID)";
                mysql_free_result($result);
        }
 
        $years = getYears( $row );
}
elseif( $enttype == "F" ) {
        $typestr = "family";
        $query = "SELECT familyID, husband, wife, living, marrdate, gedcom, branch FROM $families_table WHERE familyID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
 
        $rightbranch = checkbranch( $row[branch] ) ? 1 : 0;
        $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
        $name = "$text[family]: " . getFamilyName( $row );
       
        $years = "";
}
elseif( $enttype == "S" ) {
        $query = "SELECT title FROM $sources_table WHERE sourceID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
       
        $query = "SELECT count(personID) as ccount FROM $citations_table, $people_table
                WHERE $citations_table.sourceID = '$ID' AND $citations_table.persfamID = $people_table.personID AND $citations_table.gedcom = $people_table.gedcom
                AND living = '1'";
        $sresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $srow = mysql_fetch_assoc( $sresult );
        $row[living] = $srow[ccount] ? 1 : 0;
       
        if( !$row[living] || $livedefault == 2 || ( !$livedefault && $allow_living_db && ( !$assignedtree || $assignedtree == $row[gedcom] ) ) )
                $row[allow_living] = 1;
        else
                $row[allow_living] = 0;
        mysql_free_result( $sresult );
       
        $name = "$text[source]: $row[title] ($ID)";
        $years = "";
}
elseif( $enttype == "R" ) {
        $query = "SELECT reponame FROM $repositories_table WHERE repoID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
       
        $row[living] = 0;
        $row[allow_living] = 1;
       
        $name = "$text[repository]: $row[reponame] ($ID)";
}
if( $enttype ) {
        $flags[tabs] = $tngconfig[tabs];
        $headline = "$text[suggestchange]: $name";
        $comments = $text[comments];
        tng_header( $headline, $flags );
       
        $photostr = showSmallPhoto( $ID, $name, $row[allow_living], 0 );
        echo tng_DrawHeading( $photostr, $name, $years );
        echo tng_coreicons();
        $innermenu = "  \n";
        echo tng_menu( $enttype, "suggest", $ID, $innermenu );
        $buttontext = $text[submitsugg];
}
else {
        $headline = $text[contactus];
        $comments = $text[comments2];
        tng_header( $headline, $flags );
?>
 
<p class="header"><img src="<?php echo $cms[tngpath]; ?>tng_contact.gif" width="20" height="20" alt="" style="vertical-align:-2px" /> <?php echo $headline; ?></p><br clear="left"/>
<?php
        echo tng_coreicons();
        $buttontext = $text['sendmsg'];
}
 
if( $message ) {
        $newmessage = $text[$message];
        if( $message == "mailnotsent" ) {
                $newmessage = ereg_replace( "xxx", $sowner, $newmessage );
                $newmessage = ereg_replace( "yyy", $ssendemail, $newmessage );
        }
        echo "<p class=\"normal\"><strong><font color=\"red\">$newmessage</font></strong></p>\n";
}
 
if( $enttype )
        echo "<span class=\"subhead\"><b>$headline</b></span><br /><br />\n";
?>
 
<?php
@include($cms['tngpath'] . "TNG_captcha.php");
 
$formstr = getFORM( "tngsendmail", "post\" onsubmit=\"return validateForm();", "suggest", "suggest" );
echo $formstr;
?>
<input type="hidden" name="<?php echo $typestr; ?>ID" value="<?php echo $ID; ?>" />
<input type="hidden" name="tree" value="<?php echo $tree; ?>" />
<br>
<table border="0" cellspacing="1" cellpadding="4" width="80%">
  <tr>
      <td class="fieldnameback" width="20%"><span class="fieldname"><?php echo $text[yourname]; ?>:  </span></td>
      <td class="databack" width="80%"><input type="text" name="<?php echo $_SESSION['tng_yourname']; ?>" /></td>
</tr>
<tr>
      <td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>      <td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email']; ?>" />  </span></td>
</tr>
<tr>
      <td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>      <td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email2']; ?>" />   <input type="checkbox" name="mailme" value="1" /><?php echo $text[mailme]; ?></span></td>
</tr>
<tr>
        <td class="fieldnameback" valign="top"><span class="fieldname"><?php echo $comments; ?>:  </span></td>
        <td class="databack">
                <textarea cols="60" rows="10" name="<?php echo $_SESSION['tng_comments']; ?>"></textarea>
        </td>
</tr>
<tr><td> </td><td><span class="normal"><input type="submit" value="<?php echo $buttontext; ?>" /></span></td></tr>
</table>
<p>
  <input type="hidden" name="enttype" value="<?php echo $enttype; ?>" />
  <input type="hidden" name="ID" value="<?php echo $ID; ?>" />
  <input type="hidden" name="tree" value="<?php echo $tree; ?>" /></form>
  <br />
  <br />
  <b><?php echo $text[address3]; ?></b></p>
<p> <u><?php echo $text[address]; ?> :</u><br>
  <?php echo $text[address1]; ?></p>
<p><u><?php echo $text[address2]; ?></u><br>
  <a href="mailto:l_chance@hotmail.com">l_chance@hotmail.com</a><br>
  <a href="mailto:info@lachancefamily.com">info@lachancefamily.com</a><br>
  <a href="mailto:rila@ntl.sympatico.ca">rila@ntl.sympatico.ca</a><br />
  <br />
  <?php
        tng_footer( "" );
?>
</p>
0
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22599921
wops should have placed in code section
<?php
include("begin.php");
$tngconfig['maint'] = "";
if($cms['events']){include('cmsevents.php'); cms_contact();}
include($cms['tngpath'] . "genlib.php");
$textpart = "gedcom";
include($cms['tngpath'] . "getlang.php");
include($cms['tngpath'] . "$mylanguage/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
if($enttype)
        include($cms['tngpath'] . "checklogin.php");
else
        $currentuser = $_SESSION[currentuser];
 
$_SESSION['tng_email'] = generatePassword(1);
$_SESSION['tng_comments'] = generatePassword(1);
$_SESSION['tng_yourname'] = generatePassword(1);
 
$flags[scripting] = "<script type=\"text/javascript\">
function validateForm() {
        if( document.suggest." . $_SESSION['tng_yourname'] . ".value == \"\" ) {
                alert(\"$text[entername]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_email'] . ".value.length == 0 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\".\") < 1 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\"@\") <= 0 ) {
                alert(\"$text[enteremail]\");
                return false;
        }
        if(document.suggest." . $_SESSION['tng_email'] . ".value != document.suggest." . $_SESSION['tng_email2'] . ".value)
        {
                alert(\"$text[enteremail]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_comments'] . ".value == \"\" ) {
                alert(\"$text[entercomments]\");
                return false;
        }
        return true;
}
</script>\n";
 
if( $enttype == "I" ) {
        $typestr = "person";
        $query = "SELECT firstname, lnprefix, lastname, prefix, suffix, sex, nameorder, living, branch, disallowgedcreate, IF(birthdatetr !='0000-00-00',YEAR(birthdatetr),YEAR(altbirthdatetr)) as birth, IF(deathdatetr !='0000-00-00',YEAR(deathdatetr),YEAR(burialdatetr)) as death 
                FROM $people_table, $trees_table WHERE personID = \"$ID\" AND $people_table.gedcom = \"$tree\" AND $people_table.gedcom = $trees_table.gedcom";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        if( $result ) {
                $row = mysql_fetch_assoc($result);
                $rightbranch = checkbranch( $row[branch] );
                $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
                $disallowgedcreate = $row[disallowgedcreate];
                $name = getName( $row ) .  " ($ID)";
                mysql_free_result($result);
        }
 
        $years = getYears( $row );
}
elseif( $enttype == "F" ) {
        $typestr = "family";
        $query = "SELECT familyID, husband, wife, living, marrdate, gedcom, branch FROM $families_table WHERE familyID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
 
        $rightbranch = checkbranch( $row[branch] ) ? 1 : 0;
        $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
        $name = "$text[family]: " . getFamilyName( $row );
        
        $years = "";
}
elseif( $enttype == "S" ) {
        $query = "SELECT title FROM $sources_table WHERE sourceID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        
        $query = "SELECT count(personID) as ccount FROM $citations_table, $people_table 
                WHERE $citations_table.sourceID = '$ID' AND $citations_table.persfamID = $people_table.personID AND $citations_table.gedcom = $people_table.gedcom
                AND living = '1'";
        $sresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $srow = mysql_fetch_assoc( $sresult );
        $row[living] = $srow[ccount] ? 1 : 0;
        
        if( !$row[living] || $livedefault == 2 || ( !$livedefault && $allow_living_db && ( !$assignedtree || $assignedtree == $row[gedcom] ) ) )
                $row[allow_living] = 1;
        else
                $row[allow_living] = 0;
        mysql_free_result( $sresult );
        
        $name = "$text[source]: $row[title] ($ID)";
        $years = "";
}
elseif( $enttype == "R" ) {
        $query = "SELECT reponame FROM $repositories_table WHERE repoID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        
        $row[living] = 0;
        $row[allow_living] = 1;
        
        $name = "$text[repository]: $row[reponame] ($ID)";
}
if( $enttype ) {
        $flags[tabs] = $tngconfig[tabs];
        $headline = "$text[suggestchange]: $name";
        $comments = $text[comments];
        tng_header( $headline, $flags );
        
        $photostr = showSmallPhoto( $ID, $name, $row[allow_living], 0 );
        echo tng_DrawHeading( $photostr, $name, $years );
        echo tng_coreicons();
        $innermenu = "  \n";
        echo tng_menu( $enttype, "suggest", $ID, $innermenu );
        $buttontext = $text[submitsugg];
}
else {
        $headline = $text[contactus];
        $comments = $text[comments2];
        tng_header( $headline, $flags );
?>
 
<p class="header"><img src="<?php echo $cms[tngpath]; ?>tng_contact.gif" width="20" height="20" alt="" style="vertical-align:-2px" /> <?php echo $headline; ?></p><br clear="left"/>
<?php
        echo tng_coreicons();
        $buttontext = $text['sendmsg'];
}
 
if( $message ) {
        $newmessage = $text[$message];
        if( $message == "mailnotsent" ) {
                $newmessage = ereg_replace( "xxx", $sowner, $newmessage );
                $newmessage = ereg_replace( "yyy", $ssendemail, $newmessage );
        }
        echo "<p class=\"normal\"><strong><font color=\"red\">$newmessage</font></strong></p>\n";
}
 
if( $enttype )
        echo "<span class=\"subhead\"><b>$headline</b></span><br /><br />\n";
?>
 
<?php
@include($cms['tngpath'] . "TNG_captcha.php");
 
$formstr = getFORM( "tngsendmail", "post\" onsubmit=\"return validateForm();", "suggest", "suggest" );
echo $formstr;
?>
<input type="hidden" name="<?php echo $typestr; ?>ID" value="<?php echo $ID; ?>" />
<input type="hidden" name="tree" value="<?php echo $tree; ?>" />
<br>
<table border="0" cellspacing="1" cellpadding="4" width="80%">
  <tr>
	<td class="fieldnameback" width="20%"><span class="fieldname"><?php echo $text[yourname]; ?>:  </span></td>
	<td class="databack" width="80%"><input type="text" name="<?php echo $_SESSION['tng_yourname']; ?>" /></td>
</tr>
<tr>
	<td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>	<td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email']; ?>" />  </span></td>
</tr>
<tr>
	<td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>	<td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email2']; ?>" />   <input type="checkbox" name="mailme" value="1" /><?php echo $text[mailme]; ?></span></td>
</tr>
<tr>
        <td class="fieldnameback" valign="top"><span class="fieldname"><?php echo $comments; ?>:  </span></td>
        <td class="databack">
                <textarea cols="60" rows="10" name="<?php echo $_SESSION['tng_comments']; ?>"></textarea>
        </td>
</tr>
<tr><td> </td><td><span class="normal"><input type="submit" value="<?php echo $buttontext; ?>" /></span></td></tr>
</table>
<p> 
  <input type="hidden" name="enttype" value="<?php echo $enttype; ?>" />
  <input type="hidden" name="ID" value="<?php echo $ID; ?>" />
  <input type="hidden" name="tree" value="<?php echo $tree; ?>" /></form> 
  <br />
  <br />
  <b><?php echo $text[address3]; ?></b></p>
<p> <u><?php echo $text[address]; ?> :</u><br>
  <?php echo $text[address1]; ?></p>
<p><u><?php echo $text[address2]; ?></u><br>
  <a href="mailto:l_chance@hotmail.com">l_chance@hotmail.com</a><br>
  <a href="mailto:info@lachancefamily.com">info@lachancefamily.com</a><br>
  <a href="mailto:rila@ntl.sympatico.ca">rila@ntl.sympatico.ca</a><br />
  <br />
  <?php
        tng_footer( "" );
?>
</p>

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:theresel
ID: 22600163
Okay I've replaced with suggested functions and tried it but the email is sending even if I don't enter the right email in the second field.

The code I used for the additional field is:
<tr><td class="fieldnameback"><span class="fieldname"><?php echo $text[email2]; ?>:&nbsp; </span></td><td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email2']; ?>" /></span></td></tr>

Maybe I have to add something to the tngsendmail.php also??  Here's the code:
<?php
include("begin.php");
include($cms['tngpath'] . "genlib.php");
$textpart = "gedcom";
//include($cms['tngpath'] . "getlang.php");
include($cms['tngpath'] . "$language/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
if($enttype)
	include($cms['tngpath'] . "checklogin.php");
include($subroot . "logconfig.php");
 
$valid_user_agent = isset($_SERVER["HTTP_USER_AGENT"]) && $_SERVER["HTTP_USER_AGENT"] != "";
 
$emailfield = $_SESSION['tng_email'];
eval("\$youremail = \$$emailfield;");
$_SESSION['tng_email'] = "";
session_unregister('tng_email');
 
$commentsfield = $_SESSION['tng_comments'];
eval("\$comments = \$$commentsfield;");
$_SESSION['tng_comments'] = "";
session_unregister('tng_comments');
 
$yournamefield = $_SESSION['tng_yourname'];
eval("\$yourname = \$$yournamefield;");
$_SESSION['tng_yourname'] = "";
session_unregister('tng_yourname');
 
$tngwebsite = $cms[support] ? "http://". $_SERVER['HTTP_HOST'] : $tngdomain;
 
if( eregi("\n[[:space:]]*(to|bcc|cc|boundary)[[:space:]]*[:|=].*@", $youremail) || eregi("[\r|\n][[:space:]]*(to|bcc|cc|boundary)[[:space:]]*[:|=].*@", $yourname) || !$valid_user_agent )
	die("sorry!");
if(eregi("\r", $youremail) || eregi("\n", $youremail) || eregi("\r", $yourname) || eregi("\n", $yourname) )
	die("sorry!");
 
$youremail = strtok( $youremail, ",; " );
if( !$youremail || !$comments || !$yourname ) die("sorry!");
 
if( $addr_exclude ) {
	$bad_addrs = explode(",", $addr_exclude);
	foreach( $bad_addrs as $bad_addr ) {
		if( $bad_addr ) {
			if( strstr( $youremail, trim($bad_addr) ) )
				die("sorry");
		}
	}
}
 
if( $msg_exclude ) {
	$bad_msgs = explode(",", $msg_exclude);
	foreach( $bad_msgs as $bad_msg ) {
		if( $bad_msg ) {
			if( strstr( $comments, trim($bad_msg) ) )
				die("sorry");
		}
	}
}
 
$suggest_url = getURL( "suggest", 1 );
 
if( $enttype == "I" ) {
	$typestr = "person";
	$query = "SELECT firstname, lnprefix, lastname, prefix, suffix, sex, nameorder, living, branch, disallowgedcreate, IF(birthdatetr !='0000-00-00',YEAR(birthdatetr),YEAR(altbirthdatetr)) as birth, IF(deathdatetr !='0000-00-00',YEAR(deathdatetr),YEAR(burialdatetr)) as death
		FROM $people_table, $trees_table WHERE personID = \"$ID\" AND $people_table.gedcom = \"$tree\" AND $people_table.gedcom = $trees_table.gedcom";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	$rightbranch = checkbranch( $row[branch] );
	$row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
	$name = getName( $row ) . " ($ID)";
	$link = "$tngwebsite/" . getURL("getperson", 1) . "personID=$ID&tree=$tree";
	mysql_free_result($result);
}
elseif( $enttype == "F" ) {
	$typestr = "family";
	$query = "SELECT familyID, husband, wife, living, marrdate, gedcom, branch FROM $families_table WHERE familyID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	$rightbranch = checkbranch( $row[branch] ) ? 1 : 0;
	$row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
	$name = "$text[family]: " . getFamilyName( $row );
	$link = "$tngwebsite/" . getURL("familygroup", 1) . "familyID=$ID&tree=$tree";
	mysql_free_result($result);
}
elseif( $enttype == "S" ) {
	$query = "SELECT title FROM $sources_table WHERE sourceID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	$name = "$text[source]: $row[title] ($ID)";
	$link = "$tngwebsite/" . getURL("showsource", 1) . "sourceID=$ID&tree=$tree";
	mysql_free_result($result);
}
elseif( $enttype == "R" ) {
	$query = "SELECT reponame FROM $repositories_table WHERE repoID = \"$ID\" AND gedcom = \"$tree\"";
	$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$row = mysql_fetch_assoc($result);
	$name = "$text[repository]: $row[reponame] ($ID)";
	$link = "$tngwebsite/" . getURL("showrepo", 1) . "repoID=$ID&tree=$tree";
	mysql_free_result($result);
}
if( $enttype ) {
	$subject = "$text[proposed]: $name";
	$query = "SELECT treename FROM $trees_table WHERE gedcom=\"$tree\"";
	$treeresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$treerow = mysql_fetch_assoc( $treeresult );
 
	$body = "$text[proposed]: $name\n$text[tree]: $treerow[treename]\n$text[link]: $link\n\n$text[description]: " . stripslashes($comments) . "\n\n$yourname\n$youremail";
 
	$query = "SELECT email, owner FROM $trees_table WHERE gedcom=\"$tree\"";
	$treeresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
	$treerow = mysql_fetch_assoc( $treeresult );
	$sendemail = $treerow[email] ? $treerow[email] : $emailaddr;
	$owner = $treerow[owner] ? $treerow[owner] : ($sitename ? $sitename : $dbowner);
}
else {
	$subject = $text[comments2];
	$body = "$text[comments2]: " . stripslashes($comments) . "\n\n$yourname\n$youremail";
 
	$sendemail = $emailaddr;
	$owner = $sitename ? $sitename : $dbowner;
}
if($currentuser)
	$body .= "\n$text[user]: $currentuserdesc ($currentuser)";
 
if( $charset ) {
	$body = "<html>\n<head>\n<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\">\n</head>\n<body>\n" . nl2br($body) . "</body>\n</html>\n";
	$headers = "MIME-Version: 1.0\nContent-type: text/html; charset=$charset\nFrom: $yourname <$youremail>\nReply-to: $youremail\nReturn-Path: $emailaddr";
}
else
	$headers = "From: $yourname <$youremail>\nReply-to: $youremail\nReturn-Path: $emailaddr";
 
$success = @mail( $sendemail, $subject, $body, $headers );
if( $success ) {
	$message = "mailsent";
	if( $mailme ) {
		if($charset)
			$headers = "MIME-Version: 1.0\nContent-type: text/html; charset=$charset\nFrom: $yourname <$youremail>\nReply-to: $youremail\nReturn-Path: $youremail";
		else
			$headers = "From: $yourname <$youremail>\nReply-to: $youremail\nReturn-Path: $youremail";
		@mail( $youremail, $subject, $body, $headers );
	}
}
else
	$message = "mailnotsent&sowner=$owner&ssendemail=$sendemail";
header( "Location: $suggest_url" . "enttype=$enttype&ID=$ID&tree=$tree&message=" . urlencode($message) );
?>

Open in new window

0
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22600483
please use the code i supplied in my last response.
0
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22600489
also can you give me the link to the page you are testing this on.
0
 

Author Comment

by:theresel
ID: 22600592
Okay, I've copied your code again and it is still not working, email is sent regardless of what is entered in the second field.  

The link to the page is: www.lachancefamily.com/genealogy/suggest3.php.
(named it suggest3 for now in order not to overwrite my existing contact page until everything works).

Please not you will have to enter a captcha text first.
0
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 22601305
The code isn't assigning a value to the name. I have a fix for this. 1 sec.
0
 
LVL 10

Accepted Solution

by:
Tyler Laczko earned 500 total points
ID: 22601340
upload this.
<?php
include("begin.php");
$tngconfig['maint'] = "";
if($cms['events']){include('cmsevents.php'); cms_contact();}
include($cms['tngpath'] . "genlib.php");
$textpart = "gedcom";
include($cms['tngpath'] . "getlang.php");
include($cms['tngpath'] . "$mylanguage/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
if($enttype)
        include($cms['tngpath'] . "checklogin.php");
else
        $currentuser = $_SESSION[currentuser];
 
$_SESSION['tng_email'] = generatePassword(1);
$_SESSION['tng_comments'] = generatePassword(1);
$_SESSION['tng_yourname'] = generatePassword(1);
 
$flags[scripting] = "<script type=\"text/javascript\">
function validateForm() {
        if( document.suggest." . $_SESSION['tng_yourname'] . ".value == \"\" ) {
                alert(\"$text[entername]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_email'] . ".value.length == 0 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\".\") < 1 || document.suggest." . $_SESSION['tng_email'] . ".value.indexOf(\"@\") <= 0 ) {
                alert(\"$text[enteremail]\");
                return false;
        }
        if(document.suggest." . $_SESSION['tng_email'] . ".value != document.suggest." . $_SESSION['tng_email'] . "conf.value)
        {
                alert(\"$text[enteremail]\");
                return false;
        }
        if( document.suggest." . $_SESSION['tng_comments'] . ".value == \"\" ) {
                alert(\"$text[entercomments]\");
                return false;
        }
        return true;
}
</script>\n";
 
if( $enttype == "I" ) {
        $typestr = "person";
        $query = "SELECT firstname, lnprefix, lastname, prefix, suffix, sex, nameorder, living, branch, disallowgedcreate, IF(birthdatetr !='0000-00-00',YEAR(birthdatetr),YEAR(altbirthdatetr)) as birth, IF(deathdatetr !='0000-00-00',YEAR(deathdatetr),YEAR(burialdatetr)) as death 
                FROM $people_table, $trees_table WHERE personID = \"$ID\" AND $people_table.gedcom = \"$tree\" AND $people_table.gedcom = $trees_table.gedcom";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        if( $result ) {
                $row = mysql_fetch_assoc($result);
                $rightbranch = checkbranch( $row[branch] );
                $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
                $disallowgedcreate = $row[disallowgedcreate];
                $name = getName( $row ) .  " ($ID)";
                mysql_free_result($result);
        }
 
        $years = getYears( $row );
}
elseif( $enttype == "F" ) {
        $typestr = "family";
        $query = "SELECT familyID, husband, wife, living, marrdate, gedcom, branch FROM $families_table WHERE familyID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
 
        $rightbranch = checkbranch( $row[branch] ) ? 1 : 0;
        $row[allow_living] = !$row[living] || $livedefault == 2 || ( $allow_living && $rightbranch ) ? 1 : 0;
        $name = "$text[family]: " . getFamilyName( $row );
        
        $years = "";
}
elseif( $enttype == "S" ) {
        $query = "SELECT title FROM $sources_table WHERE sourceID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        
        $query = "SELECT count(personID) as ccount FROM $citations_table, $people_table 
                WHERE $citations_table.sourceID = '$ID' AND $citations_table.persfamID = $people_table.personID AND $citations_table.gedcom = $people_table.gedcom
                AND living = '1'";
        $sresult = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $srow = mysql_fetch_assoc( $sresult );
        $row[living] = $srow[ccount] ? 1 : 0;
        
        if( !$row[living] || $livedefault == 2 || ( !$livedefault && $allow_living_db && ( !$assignedtree || $assignedtree == $row[gedcom] ) ) )
                $row[allow_living] = 1;
        else
                $row[allow_living] = 0;
        mysql_free_result( $sresult );
        
        $name = "$text[source]: $row[title] ($ID)";
        $years = "";
}
elseif( $enttype == "R" ) {
        $query = "SELECT reponame FROM $repositories_table WHERE repoID = \"$ID\" AND gedcom = \"$tree\"";
        $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        
        $row[living] = 0;
        $row[allow_living] = 1;
        
        $name = "$text[repository]: $row[reponame] ($ID)";
}
if( $enttype ) {
        $flags[tabs] = $tngconfig[tabs];
        $headline = "$text[suggestchange]: $name";
        $comments = $text[comments];
        tng_header( $headline, $flags );
        
        $photostr = showSmallPhoto( $ID, $name, $row[allow_living], 0 );
        echo tng_DrawHeading( $photostr, $name, $years );
        echo tng_coreicons();
        $innermenu = "  \n";
        echo tng_menu( $enttype, "suggest", $ID, $innermenu );
        $buttontext = $text[submitsugg];
}
else {
        $headline = $text[contactus];
        $comments = $text[comments2];
        tng_header( $headline, $flags );
?>
 
<p class="header"><img src="<?php echo $cms[tngpath]; ?>tng_contact.gif" width="20" height="20" alt="" style="vertical-align:-2px" /> <?php echo $headline; ?></p><br clear="left"/>
<?php
        echo tng_coreicons();
        $buttontext = $text['sendmsg'];
}
 
if( $message ) {
        $newmessage = $text[$message];
        if( $message == "mailnotsent" ) {
                $newmessage = ereg_replace( "xxx", $sowner, $newmessage );
                $newmessage = ereg_replace( "yyy", $ssendemail, $newmessage );
        }
        echo "<p class=\"normal\"><strong><font color=\"red\">$newmessage</font></strong></p>\n";
}
 
if( $enttype )
        echo "<span class=\"subhead\"><b>$headline</b></span><br /><br />\n";
?>
 
<?php
@include($cms['tngpath'] . "TNG_captcha.php");
 
$formstr = getFORM( "tngsendmail", "post\" onsubmit=\"return validateForm();", "suggest", "suggest" );
echo $formstr;
?>
<input type="hidden" name="<?php echo $typestr; ?>ID" value="<?php echo $ID; ?>" />
<input type="hidden" name="tree" value="<?php echo $tree; ?>" />
<br>
<table border="0" cellspacing="1" cellpadding="4" width="80%">
  <tr>
	<td class="fieldnameback" width="20%"><span class="fieldname"><?php echo $text[yourname]; ?>:  </span></td>
	<td class="databack" width="80%"><input type="text" name="<?php echo $_SESSION['tng_yourname']; ?>" /></td>
</tr>
<tr>
	<td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>	<td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email']; ?>" />  </span></td>
</tr>
<tr>
	<td class="fieldnameback"><span class="fieldname"><?php echo $text[email]; ?>:  </span></td>	<td class="databack"><span class="normal"><input type="text" name="<?php echo $_SESSION['tng_email']; ?>conf" />   <input type="checkbox" name="mailme" value="1" /><?php echo $text[mailme]; ?></span></td>
</tr>
<tr>
        <td class="fieldnameback" valign="top"><span class="fieldname"><?php echo $comments; ?>:  </span></td>
        <td class="databack">
                <textarea cols="60" rows="10" name="<?php echo $_SESSION['tng_comments']; ?>"></textarea>
        </td>
</tr>
<tr><td> </td><td><span class="normal"><input type="submit" value="<?php echo $buttontext; ?>" /></span></td></tr>
</table>
<p> 
  <input type="hidden" name="enttype" value="<?php echo $enttype; ?>" />
  <input type="hidden" name="ID" value="<?php echo $ID; ?>" />
  <input type="hidden" name="tree" value="<?php echo $tree; ?>" /></form> 
  <br />
  <br />
  <b><?php echo $text[address3]; ?></b></p>
<p> <u><?php echo $text[address]; ?> :</u><br>
  <?php echo $text[address1]; ?></p>
<p><u><?php echo $text[address2]; ?></u><br>
  <a href="mailto:l_chance@hotmail.com">l_chance@hotmail.com</a><br>
  <a href="mailto:info@lachancefamily.com">info@lachancefamily.com</a><br>
  <a href="mailto:rila@ntl.sympatico.ca">rila@ntl.sympatico.ca</a><br />
  <br />
  <?php
        tng_footer( "" );
?>
</p>

Open in new window

0
 

Author Comment

by:theresel
ID: 22604404
This is working like a charm, thank you very much for your help.
0
 

Author Closing Comment

by:theresel
ID: 31501327
You're a genious!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question