Hello Raidersguy,
Here's a step by step description on how to add an extra field.
The changes and line numbers are for the original GBook version 1.43.
The newfield I have introduced is named
newfield1
Where the name of the field is printed in the guestbook I have used the name
newfield1_name, this can be changed to whatever you want.
Change (starting at line 71)
Code: Select all
$name=gbook_input($_POST['name']);
$from=gbook_input($_POST['from']);
$a=check_mail_url(); $email=$a['email']; $url=$a['url'];
$comments=gbook_input($_POST['comments']);
$isprivate=gbook_input($_POST['private']);
if ($isprivate) {$sign_isprivate='checked';}
if ($_REQUEST['nosmileys']) {$sign_nosmileys='checked';}
if (empty($name))
{
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,'Please enter your name');
}
if ($email=='INVALID')
{
printSign($name,$from,'',$url,$comments,$sign_nosmileys,$sign_isprivate,'Enter a valid e-mail address or leave it empty');
}
if ($url=='INVALID')
{
printSign($name,$from,$email,'',$comments,$sign_nosmileys,$sign_isprivate,'Enter a valid website address or leave it empty');
}
if (empty($comments))
{
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,'Please enter your comments');
}
to this
Code: Select all
$name=gbook_input($_POST['name']);
$from=gbook_input($_POST['from']);
$a=check_mail_url(); $email=$a['email']; $url=$a['url'];
$comments=gbook_input($_POST['comments']);
$isprivate=gbook_input($_POST['private']);
$newfield1=gbook_input($_POST['newfield1']);
if ($isprivate) {$sign_isprivate='checked';}
if ($_REQUEST['nosmileys']) {$sign_nosmileys='checked';}
if (empty($name))
{
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Please enter your name');
}
if ($email=='INVALID')
{
printSign($name,$from,'',$url,$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Enter a valid e-mail address or leave it empty');
}
if ($url=='INVALID')
{
printSign($name,$from,$email,'',$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Enter a valid website address or leave it empty');
}
if (empty($comments))
{
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Please enter your comments');
}
Change (line 103)
Code: Select all
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,'Please enter the security number');
to
Code: Select all
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Please enter the security number');
and change (line 108)
Code: Select all
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,'Wrong security number');
to
Code: Select all
printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,$newfield1,'Wrong security number');
Change (line 124)
Code: Select all
addEntry($name,$from,$email,$url,$comments,$isprivate);
to
Code: Select all
addEntry($name,$from,$email,$url,$comments,$isprivate,$newfield1);
Change (line 353)
Code: Select all
function print_secimg($name,$from,$email,$url,$comments,$isprivate,$message=0) {
to
Code: Select all
function print_secimg($name,$from,$email,$url,$comments,$isprivate,$newfield1,$message=0) {
Add (after line 383, which is the following line)
Code: Select all
<input type="hidden" name="private" value="<?php echo $isprivate; ?>">
the following code (it does not have to be at that line exactly but must be somewhere in that paragraph with the other "hidden" input fields)
Code: Select all
<input type="hidden" name="newfield1" value="<?php echo $newfield1; ?>">
Change (line 430)
Code: Select all
list($name,$from,$email,$url,$comment,$added,$isprivate,$reply)=explode($delimiter,$lines[$num]);
to (notice that
,$ip,$newfield1 is added and not only $newfield)
Code: Select all
list($name,$from,$email,$url,$comment,$added,$isprivate,$reply,$ip,$newfield1)=explode($delimiter,$lines[$num]);
Add after (starting at line 448)
Code: Select all
if ($email)
{
echo '<font class="smaller">E-mail:</font> <a href="mailto:'.$email.'" target="_blank" class="smaller">'.$email.'</a>';
}
the following code (it can also be placed before the previous lines of code, depending on where you want the field to be displayed in the private messages)
Code: Select all
if ($newfield1)
{
echo '<font class="smaller">newfield1_name: '.$newfield1.'</font><br>';
}
Change (line 607)
Code: Select all
function addEntry($name,$from,$email,$url,$comments,$isprivate="0") {
to
Code: Select all
function addEntry($name,$from,$email,$url,$comments,$isprivate="0",$newfield1) {
Change (line 632), these are the fields that are added to the entries.txt file
Code: Select all
$addline = $name.$delimiter.$from.$delimiter.$email.$delimiter.$url.$delimiter.$comments.$delimiter.$added.$delimiter.$isprivate.$delimiter.'0'.$delimiter.$_SERVER['REMOTE_ADDR']."\n";
to
Code: Select all
$addline = $name.$delimiter.$from.$delimiter.$email.$delimiter.$url.$delimiter.$comments.$delimiter.$added.$delimiter.$isprivate.$delimiter.'0'.$delimiter.$_SERVER['REMOTE_ADDR'].$delimiter.$newfield1."\n";
Add a new line somewhere in this code (starting at line 651)
Code: Select all
Name: $name
From: $from
E-mail: $email
Website: $url
with the following code (this is adding the new field to the notifying mail)
Change (line 686)
Code: Select all
function printSign($name='',$from='',$email='',$url='',$comments='',$nosmileys='',$isprivate='',$error='') {
to
Code: Select all
function printSign($name='',$from='',$email='',$url='',$comments='',$nosmileys='',$isprivate='',$newfield1='',$error='') {
Add after (starting at line 713)
Code: Select all
<tr>
<td>Your e-mail:</td>
<td><input type="text" name="email" size="30" maxlength="50" value="<?php echo $email; ?>"></td>
</tr>
The following code can also be added before that piece of code but has to be an entire table row ( <tr>...</tr> ). This is the field in the "sign guestbook" page
Code: Select all
<tr>
<td>newfield1_name:</td>
<td><input type="text" name="newfield1" size="30" maxlength="50" value="<?php echo $newfield1; ?>"></td>
</tr>
Change (line 779)
Code: Select all
list($name,$from,$email,$url,$comment,$added,$isprivate,$reply)=explode($delimiter,$lines[$i]);
to (notice that
,$ip,$newfield1 is added and not only $newfield)
Code: Select all
list($name,$from,$email,$url,$comment,$added,$isprivate,$reply,$ip,$newfield1)=explode($delimiter,$lines[$i]);
Add after (starting at line 796)
Code: Select all
if ($email)
{
echo '<font class="smaller">E-mail:</font> <a href="mailto:'.$email.'" target="_blank" class="smaller">'.$email.'</a><br>';
}
the following code (it can also be placed before that code, depending on where you want the line with the new field to be displayed in the guestbook)
Code: Select all
if ($newfield1)
{
echo '<font class="smaller">newfield1_name: '.$newfield1.'</font><br>';
}
This should be everything and works in my test guestbook.
I just hope I have not made an error when I added all this to this forum.
Greetings,
Henrie