Adding a field to the comment form

Creating and modifying plugins.
Post Reply
dgee
Posts: 4
Joined: Sun Jan 09, 2011 6:11 am

Adding a field to the comment form

Post by dgee »

I want to add the field " location" as in city state country to the comment form so I will know where the comments originate geographically. I have looked at the comment plugin and can't figure out how to get this to show up. Can any one help with this coding issue? I would sure appreciate it.
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Adding a field to the comment form

Post by yellowled »

dgee wrote:I want to add the field " location" as in city state country to the comment form so I will know where the comments originate geographically.
You're gonna have to add that field to your template's commentform.tpl manually using Smarty. If your template doesn't have that file, just copy the one from /templates/default/ to /templates/YOUR_TEMPLATE/ and edit the copied file.

YL
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Adding a field to the comment form

Post by onli »

Will that be saved in the database, is the content of a saved comment written dynamic enough?
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Adding a field to the comment form

Post by yellowled »

onli wrote:Will that be saved in the database, is the content of a saved comment written dynamic enough?
Good point. Thinking about it, I guess it won't. Hmpf.

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding a field to the comment form

Post by garvinhicking »

Hi!

Indeed, adding a new field for that would require at best a complete event plugin that extends all hooks to read, write and display comments, as well as introduce its own database for storage..

Maybe if you could get rid of one of the other fields (like homepage or email address) you could put the contents of location into it just be relabelling the field...otherwise, that would mean a bit more of coding effort. How proficient are you with PHP, would you want to try this coding with help from us?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
dgee
Posts: 4
Joined: Sun Jan 09, 2011 6:11 am

Re: Adding a field to the comment form

Post by dgee »

Well not that proficient at all I could do without the commented homepage for the website I am using it on if I had to. This is my first time using this software so I am not terrible familiar with any of it. Any and all help would be fantastic :) you can see where I am using this at jamesshelnut.com it is the competition template I add the template but your right it doesn't insert it into the database even tho I added a table for it. I am not quite sure how to get it to that and then show up when the comments are read.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding a field to the comment form

Post by garvinhicking »

Hi!

Okay, in that case you could simply rename the "Homepage" field and set it to read "Region".

To do that, you need to edit two files of the competition template. The template does not come with individual template files, so first you need to copy "commentform.tpl" and "comments.tpl" from the templates/default/ directory to templates/competition.

Once those files are there, edit the commentform.tpl. Inside the file you can see this code:

Code: Select all

        <tr>
            <td class="serendipity_commentsLabel"><label for="serendipity_commentform_url">{$CONST.HOMEPAGE}</label></td>
            <td class="serendipity_commentsValue"><input type="text" id="serendipity_commentform_url" name="serendipity[url]" value="{$commentform_url}" /></td>
        </tr>
this currently displays the input area for the homepage. You can change this to:

Code: Select all

        <tr>
            <td class="serendipity_commentsLabel"><label for="serendipity_commentform_url">Your Region (geo)</label></td>
            <td class="serendipity_commentsValue"><input type="text" id="serendipity_commentform_url" name="serendipity[url]" value="{$commentform_url}" /></td>
        </tr>
Note how we only change the title of the label, and not any of the input fields, because it all refers to the internal database structure.

Now the same for comments.tpl. Find this part:

Code: Select all

            {if $comment.url}
                (<a class="comment_source_url" href="{$comment.url}" title="{$comment.url|@escape}">{$CONST.HOMEPAGE}</a>)
            {/if}
and change it to:

Code: Select all

            {if $comment.url}
                (Region: {$comment.url|@escape})
            {/if}
Also note here that we remove formerly used href's for the real url, but still use the "url" field name to display the region. how and where you place the region is up to you, you can move that line of code to another place or style it with CSS/HTML markup as you wish.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
dgee
Posts: 4
Joined: Sun Jan 09, 2011 6:11 am

Re: Adding a field to the comment form

Post by dgee »

I tried that but it distorted the comments template and gave me errors.... also the region/ location came up as a http:// region

Any other idea?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding a field to the comment form

Post by garvinhicking »

Hi!

You most probably have not replaced the contents properly, I'm sorry. Copy&Paste the resulting file here and I'll try to spot where the error could be.

The "http://" thing is true, I forgot about this. It gets added because s9y normally thinks a URL should be there. In your tepmlate you can fix that by using

Code: Select all

(Region: {$comment.url|@escape|replace:'http://':''})
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
dgee
Posts: 4
Joined: Sun Jan 09, 2011 6:11 am

Re: Adding a field to the comment form

Post by dgee »

Thanks Garvin
I totally replaced the two pages with a fresh copy, with the new code and everything works great! Your help was extremely invaluable.
Tami
Post Reply