Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[HOW TO] Add additional fields
Dody
Join Date: Jul 2004
Posts: 7

by Dody Dody is offline 10 Mar 2010
Rating: (2 votes - 5.00 average)

This guide will show you how to add additional fields to your threads. This feature has been requested many many times and can be very powerfull.

Imagine that you want to add additional fields to your threads, such that every time a user create a new thread has the opportunity to fill these fields. This requires HTML and PHP experience, so be prepared!


Add additional fields

The very first step is to the the HTML code of the additional fields into newthread template. This can be done by adding HTML code directly into the HTML code right after the Title field:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

For instance you can add:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Or you can add a variable ({vb:raw additionalfields}) and render newthread template to add these fields automatically from a plugin (if you don't know how, go for adding the HTML code or do some homework )


Catch additional fields values

Now that you have add some fields to newthread template, you need to catch them before adding them to the database. This can simply be done by hooking newthread_post_start and catching the field value:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Where additionalField is HTML name attribute of the additional field we added above.


Add additional fields values to post/database

Now we have catched the field value ($value) and are ready to save it to the database or to the post.

Personally I prefer to add it to the post, because it will be searchable by default and can be done very easily (easier than adding it to an extra database table)

Once you cashed the field variable as described above, you can add it to the post by:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Extra BBcodes

If you want to wrap $value with some extra HTML codes, then you need to create some custom BBcodes and wrap it around the value:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This requires that you add the BBcodes manually before everything else.


Case study
Let's say we want to add an additonal field that will carry the source URL of an article.

First we add:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

to newthread template as described above

Then create a plugin (something similar to the following).


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Or download it from the attachment below. Add it through Admincp -> Plugins & Products -> Manage products, and [Add/Import Product]

And you are done!

Note: the plugin is just to show you how this works and by no mean is supported or ready for production.

Got a question, suggestion or improvment? don't hesitate to let me know
Views: 11678
Reply With Quote
Comments
  #2  
Old 12 Mar 2010, 17:35
MARCO1's Avatar
MARCO1 MARCO1 is offline
 
Join Date: Jun 2008
Real name: Marco
Nice Guide, Thanks.
__________________
Marco Mamdouh Fahem.
OUZMind Lead Developers
vBFoster Lead Developers
vBulletin 5 Alpha Team member.
Reply With Quote
  #3  
Old 13 Mar 2010, 04:33
nader nader is offline
 
Join Date: Feb 2004
what about CMS additional fields?
Reply With Quote
  #4  
Old 13 Mar 2010, 09:57
Dody Dody is offline
 
Join Date: Jul 2004
I don't think that CMS has enough hooks to do the above, but as Edwin Brown blogged, you can create your own content type which includes the number of fields that suites your need.
Reply With Quote
  #5  
Old 17 Apr 2010, 01:25
weallgovern weallgovern is offline
 
Join Date: Apr 2010
great can this be done for individual forum categories? For example not in lobby forum but in forum a b and z etc.
Reply With Quote
  #6  
Old 29 Apr 2010, 23:24
Dody Dody is offline
 
Join Date: Jul 2004
Originally Posted by weallgovern View Post
great can this be done for individual forum categories? For example not in lobby forum but in forum a b and z etc.
Yes it is possible. In the newthread template you can use


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Similary in the plugin code, you can add:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #7  
Old 04 May 2010, 03:18
as7apcool's Avatar
as7apcool as7apcool is offline
 
Join Date: Feb 2009
thanks alot for your good work
Reply With Quote
  #8  
Old 07 Jun 2010, 16:49
bnimbhal bnimbhal is offline
 
Join Date: Jul 2009
very tough to understand.
Reply With Quote
  #9  
Old 08 Jun 2010, 19:32
wolfe wolfe is offline
 
Join Date: Jan 2002
the bbcode parsing is not working properly i use [CODE] tags and it all shows in one line.
__________________
Thanks
Reply With Quote
  #10  
Old 22 Jun 2010, 13:16
Dody Dody is offline
 
Join Date: Jul 2004
Originally Posted by wolfe View Post
the bbcode parsing is not working properly i use [CODE] tags and it all shows in one line.
I am not sure if that could be a bug in the code tag.
Reply With Quote
  #11  
Old 20 Jul 2010, 02:35
neverstop neverstop is offline
 
Join Date: Jan 2007
Can you show how to add the new value to a separate field in the thread table?

thanks in advance
Reply With Quote
  #12  
Old 28 Jul 2010, 11:46
libabom libabom is offline
 
Join Date: Dec 2005
what about CMS additional fields?
Reply With Quote
  #13  
Old 03 Sep 2010, 10:59
vbbforfree's Avatar
vbbforfree vbbforfree is offline
 
Join Date: Feb 2010
Real name: HuyHuyen
how to add field before username
Reply With Quote
  #14  
Old 04 Sep 2010, 12:55
Dody Dody is offline
 
Join Date: Jul 2004
Originally Posted by libabom View Post
what about CMS additional fields?
I would advice you to wait until custom type, which is going to be released soon.

--------------- Added 04 Sep 2010 at 12:56 ---------------

Originally Posted by vbbforfree View Post
how to add field before username
It depends on what you are trying to achieve.

Last edited by Dody; 04 Sep 2010 at 12:56. Reason: Auto-Merged DoublePost
Reply With Quote
  #15  
Old 04 Sep 2010, 22:25
nader nader is offline
 
Join Date: Feb 2004
Originally Posted by Dody View Post
I would advice you to wait until custom type, which is going to be released soon.

It depends on what you are trying to achieve.
which version it will be?

Last edited by nader; 05 Sep 2010 at 13:16.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 14:18.

Layout Options | Width: Wide Color: