Add extra fields to guest book 1.7

Everything related to GBook PHP guestbook
Gary
Posts: 1
Joined: Mon Sep 28, 2009 1:45 pm

Add extra fields to guest book 1.7

Post by Gary »

I would like to add extra fields to guest book.

I have tried without any results has anyone added two or more extra fields to the gbook.php


I am looking to add after the name field a "who to" field and also two other fields.

If anyone has added three extra fieilds to their gbook.php file please let me know.

mine is located at

http://www.garyallendj.com/request
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

Sorry for the late answer. When you posted i was to busy to answer. And after that i kinda forgot.

Adding new fields is not advised. It will make the guestbook incompatible with future upgrades.

Also it needs a lot of editing for which i just don't have the time to explain.

Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
PiPPi
Posts: 5
Joined: Sun Jan 24, 2010 9:07 am

Post by PiPPi »

Hello,

Also very much in need for adding an extra field. Really like Gbook but the one thing I need before buying a license is that extra field.

Sure, the coding might be tricky but the need is very basic, a required "Subject"-field.

Gbook is the best in it's league as far as I'm concerned. "league" meaning PHP with no SQL needed, and the mail-back at posting, the very easy modification through templates, a separate language file and very well written code in general is simply great.

I really do not want to look elsewhere so if anyone out there has added an extra required field to Gbook 1.7, please share your experiences.

Regards
PiPPi
PiPPi
Posts: 5
Joined: Sun Jan 24, 2010 9:07 am

Post by PiPPi »

Never mind, fixed the extra field and it works fine.

Regards
PiPPi
cleiton
Posts: 4
Joined: Tue Jun 07, 2011 10:57 pm

Re: Add extra fields to guest book 1.7

Post by cleiton »

Hello sir, kindly can you share your extra field fix?

Thanks in advanced
PiPPi
Posts: 5
Joined: Sun Jan 24, 2010 9:07 am

Re: Add extra fields to guest book 1.7

Post by PiPPi »

Sorry,

It was almost 18 months ago and I don't have it documented.

I'm not a programmer but what I did was to check out the codes for an existing field of the same type and then basically replicated that info where applicable (and changing the name of the field variable of course).

Regards
PiPPi
cleiton
Posts: 4
Joined: Tue Jun 07, 2011 10:57 pm

Re: Add extra fields to guest book 1.7

Post by cleiton »

That's ok, no problem!

I'm too late on this post :mrgreen:

Thanks anyway :wink:
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Add extra fields to guest book 1.7

Post by Henrie »

Because in another thread someone asked for the extra field too and because it has been asked several times more, I decided to finally post it.

But first a warning:
This modification may make the entries.txt flatfile database incompatible with future versions of the guestbook.
The content of the extra field will be stored in the entries.txt flatfile database. Newer versions of GBook may use more fields itself for extra functionality. This will make that in that case the entries.txt file -that contains contents of the extra field added by this modification- can not be used together with the newer version of GBook.

Now that you know about the possible risks of using this modification, here it goes.

Extra field for GBook version 1.7


Open the file sign_form.php
This can be found in your templates/default folder (or other template name if you created it).
This code is needed for adding the extra field to your 'sign guestbook' page.

Search for (lines 54-56)

Code: Select all

	<div class="clear"></div>

	<div class="gbook_left"><span class="gbook_entries"><b><?php echo $lang['t16']; ?></b></span></div>
Add at the empty line 55

Code: Select all

/* extra field modification by Henrie >> HL06 start */
	<div class="gbook_left"><span class="gbook_entries"><?php echo $lang['hl06_t01']; ?></span></div>
	<div class="gbook_right"><input type="text" name="extrafield1" value="<?php echo $newfield1; ?>" size="45" /></div>

	<div class="clear"></div>
/* extra field modification by Henrie >> HL06 end */
save and close the sign_form.php file.

If you want the extra field to appear in another part of the sign page, you can insert the code at another location. But it is best to put it first at this location and after making all the modifications test that it is working before you move it.


Open the file comments.php
This can be found in your templates/default folder (or other template name if you created it).
This code is needed for displaying the extra field in your guestbook page.

Search for (lines 22-25)

Code: Select all

	if ($email)
	{
		echo '<span class="gbook_submitted_by">'.$lang['t20'].' '.$email.'</span><br class="clear" />';
	}
Below it add

Code: Select all

/* extra field modification by Henrie >> HL06 start */
	if ($extrafield1)
	{
		echo '<span class="gbook_submitted_by">'.$lang['hl_t10'].' '.$extrafield1.'</span><br class="clear" />';
	}
/* extra field modification by Henrie >> HL06 end */
save and close the comments.php file.

If you want the extra field to appear in another part of the guestbook entry, you can insert the code at another location. But it is best to put it first at this location and after making all the modifications test that it is working before you move it.


Open the file gbook.php

Part 1 of 12: PrintEntries
This code is needed for reading the fields from the entries.txt file and together with comments.php file display the entries in the guestbook.

Search for (line 1079)

Code: Select all

list($name,$from,$email,$url,$comment,$added,$isprivate,$reply)=explode($delimiter,$lines[$i]);
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 1 of 12: PrintEntries start (extrafield1 added and IP to fill the gap) */		list($name,$from,$email,$url,$comment,$added,$isprivate,$reply,$IP,$extrafield1)=explode($delimiter,$lines[$i]);
/* extra field modification by Henrie >> HL06 part 1 of 12: PrintEntries end */
Part 2 of 12: PrintSign
This code is used for displaying the 'sign guestbook' page.

Search for (line 1011)

Code: Select all

function printSign($name='',$from='',$email='',$url='',$comments='',$nosmileys='',$isprivate='',$error='',$spamanswer='')
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 2 of 12: PrintSign start (extrafield1 added) */
function printSign($name='',$from='',$email='',$url='',$extrafield1='',$comments='',$nosmileys='',$isprivate='',$error='',$spamanswer='')
/* extra field modification by Henrie >> HL06 part 2 of 12: PrintSign end */
Part 3 of 12: e-mail notification
This code is used to send you an e-mail when a new entry is added

Search for (line 981)

Code: Select all

	        $message.= "$lang[t20] $email\n";
and directly below it add

Code: Select all

/* extra field modification by Henrie >> HL06 part 3 of 12: e-mail notification start (extrafield1 added) */
	        $message.= "$lang[hl06_t02] $extrafield1\n";
/* extra field modification by Henrie >> HL06 part 3 of 12: e-mail notification end */
If you want the extra field to appear in another part of the message, you can insert the code at another location. But it is best to put it first at this location and after making all the modifications test that it is working before you move it.


Part 4 of 12: approval e-mail
This code is used to send you an e-mail when you have approving of new messages activated

Search for (line 943)

Code: Select all

	        $message.= "$lang[t20] $email\n";
and directly below it add

Code: Select all

/* extra field modification by Henrie >> HL06 part 4 of 12: approval e-mail start */
	        $message.= "$lang[hl06_t02] $extrafield1\n";
/* extra field modification by Henrie >> HL06 part 4 of ?: approval e-mail end */
If you want the extra field to appear in another part of the message, you can insert the code at another location. But it is best to put it first at this location and after making all the modifications test that it is working before you move it.


Part 5 of 12: add entry
This code is used to add the entry to the flatfile database file

Search for (line 907)

Code: Select all

	$addline = $name.$delimiter.$from.$delimiter.$email.$delimiter.$url.$delimiter.$comments.$delimiter.$added.$delimiter.$isprivate.$delimiter.'0'.$delimiter.$_SERVER['REMOTE_ADDR']."\n";
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 5 of 12: add entry start (delimiter and extrafield1 added) */
	$addline = $name.$delimiter.$from.$delimiter.$email.$delimiter.$url.$delimiter.$comments.$delimiter.$added.$delimiter.$isprivate.$delimiter.'0'.$delimiter.$_SERVER['REMOTE_ADDR'].$delimiter.$extrafield1."\n";
/* extra field modification by Henrie >> HL06 part 5 of 12: add entry end */
Part 6 of 12: filter bad words
This code is used to filter any bad words using the badwords file.

Search for (line 890)

Code: Select all

		$from = filter_bad_words($from);
and add following code directly below

Code: Select all

/* extra field modification by Henrie >> HL06 part 6 of 12: filter bad words start */
		$newfield1 = filter_bad_words($newfield1); //HL06: newfield added
/* extra field modification by Henrie >> HL06 part 6 of 12: filter bad words end */
Part 7 of 12: JunkMark
This code is used to check the message with JunkMark. I do not actually know if it will check the field as I do not know the JunkMark code because it is encoded. If you do not want to use JunkMark for the extra field, than skip this.

Search for (line 860)

Code: Select all

		$junk_mark = JunkMark($name,$from,$email,$url,$comments);
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 7 of 12: JunkMark start (extrafield1 added) */
		$junk_mark = JunkMark($name,$from,$email,$url,$extrafield1,$comments);
/* extra field modification by Henrie >> HL06 part 7 of 12: JunkMark end */
Part 8 of 12: display error
This code is used to display an error message if needed.

Search for (line 854)

Code: Select all

    	printSign($name,$from,$email,$url,$comments,$sign_nosmileys,$sign_isprivate,$error_buffer,$spamanswer);
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 8 of 12: display error start (extrafield1 added) */
    	printSign($name,$from,$email,$url,$extrafield1,$comments,$sign_nosmileys,$sign_isprivate,$error_buffer,$spamanswer);
/* extra field modification by Henrie >> HL06 part 8 of 12: display error end */
Part 9 of 12: error message
This code is used to create an error message for a defined condition.
If you don't need the extra field being checked for being empty (or another condition you creat yourself), than skip this part.

Search for (lines 783-787)

Code: Select all

	if ($url=='INVALID')
	{
        $error_buffer .= $lang['e05'].'<br class="clear" />';
        $url = '';
	}
and directly below it add

Code: Select all

/* extra field modification by Henrie >> HL06 part 9 of 12: error message start */
	if (empty($extrafield1))
	{
        $error_buffer .= $lang['hl06_e01'].'<br class="clear" />';
	}
/* extra field modification by Henrie >> HL06 part 9 of 12: error message end */
Part 10 of 12: add entry
This code is used to add the entry to prepare the entry for being added to the guestbook.

Search for (lines 760)

Code: Select all

	$from = gbook_input($_POST['from']);
and directly below it add

Code: Select all

/* extra field modification by Henrie >> HL06 part 10 of 12: add entry start */
	$extrafield1 = gbook_input($_POST['extrafield1']);
/* extra field modification by Henrie >> HL06 part 10 of 12: add entry end */
Part 11 of 12: notify visitor
This code is used for the message sent to the visitor when a reply is made to his/her guestbook entry.

Search for (lines 476)

Code: Select all

        $email = $myline[2];
and directly below it add

Code: Select all

/* extra field modification by Henrie >> HL06 part 11 of 12: notify visitor start */
        $extrafield1 = $myline[9];
/* extra field modification by Henrie >> HL06 part 11 of 12: notify visitor end */
Part 12 of 12: reply message
This code is used for the reply to a message.

Search for (lines 458)

Code: Select all

	$myline = array(0=>'',1=>'',2=>'',3=>'',4=>'',5=>'',6=>'',7=>'',8=>'');
and replace it with

Code: Select all

/* extra field modification by Henrie >> HL06 part 12 of 12: reply message start (added ,9=>'') */
	$myline = array(0=>'',1=>'',2=>'',3=>'',4=>'',5=>'',6=>'',7=>'',8=>'',9=>'');
/* extra field modification by Henrie >> HL06 part 12 of 12: reply message end */
save and close the gbook.php file.


Open the file language.inc.php
Add the following code before the ?> at the end of the file:

Code: Select all

/* Language strings for modifications by Henrie */
$lang['hl06_t01']='<b>Your extra field 1:</b>'; // used for field name on sign page 
$lang['hl06_t02']='Extra field 1:'; // used for field name in E-mail and guestbook page
$lang['hl06_e01']='Please enter your name extra field 1:';
When you are not using it as a required field, than remove the <b> and </b> from the above code.

save and close the language.inc.php file.

This shoud be it.
Only basic posting has been tested. So please let me know if something does not work.

Greetings,
Henrie
Last edited by Henrie on Fri Mar 14, 2014 8:26 am, edited 1 time in total.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
cAdams
Posts: 40
Joined: Thu Sep 15, 2011 10:52 pm

Re: Add extra fields to guest book 1.7

Post by cAdams »

getting closer Henrie - unless i have incorrect scripts elsewhere

the correct error message came up when the new field was left empty (image in my case), but after clicking to submit the form with the image entered, an error message returns a blank screen

since making the script changes, i've now also lost the image field from the comments page which i had beneath the poster's name on the left of the comments box and the sign.php's new field isn't formatting correctly
To All UALs (Unreliable Arrogant Liars), Go Play On The Motorway
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Add extra fields to guest book 1.7

Post by Henrie »

the correct error message came up when the new field was left empty (image in my case), but after clicking to submit the form with the image entered, an error message returns a blank screen
The error message is not blank. Just the text is white so you can not read it on a white background. The error you get is:
Error
Can't open entries file for writing. Please CHMOD entries file to 666 (rw-rw-rw-)!:

since making the script changes, i've now also lost the image field from the comments page which i had beneath the poster's name on the left of the comments box
It is only shown when a value has been entered. Since there is not any present in the entries database (because it is not writable) it can not show anything.
and the sign.php's new field isn't formatting correctly
Check the classes class="gbook_left" and class="gbook_right" They are not as I have posted them.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
cAdams
Posts: 40
Joined: Thu Sep 15, 2011 10:52 pm

Re: Add extra fields to guest book 1.7

Post by cAdams »

WAHOO!!!!!

corrections done and now near perfect :)

just need to tweak the time now so post submitted reads NZ time instead of Germany

thanx so much for your extra time Henrie, very, very much appreciated
To All UALs (Unreliable Arrogant Liars), Go Play On The Motorway
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Add extra fields to guest book 1.7

Post by Henrie »

cAdams, you should take a look here viewtopic.php?t=2421
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
wino
Posts: 6
Joined: Wed Mar 12, 2014 8:25 am

Re: Add extra fields to guest book 1.7

Post by wino »

Hello all, great script guys :) I know this thread is quite old but i have added the extra field and it works beautifully. Just wondering if i can make my brand new field hidden just like the email. I am creating a partition and need the "real name" of the person signing not to show publicly. Also can the no_spam gif be removed? Thanks.
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Re: Add extra fields to guest book 1.7

Post by Klemen »

To hide the "no spam" banner change

Code: Select all

$settings['show_nospam'] = 1;
to

Code: Select all

$settings['show_nospam'] = 0;
in your settings file.

To hide real name simply remove the variable containing the name from the entries template (templates/default/comments.php).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
wino
Posts: 6
Joined: Wed Mar 12, 2014 8:25 am

Re: Add extra fields to guest book 1.7

Post by wino »

Thank you Klemen it worked like a charm.
Post Reply