[HOW TO] Add additional fields
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: HTML Code:
<input type="text" class="primary full textbox" name="subject" id="subject" value="{vb:raw subject}" maxlength="{vb:raw vboptions.titlemaxchars}" tabindex="1" /> HTML Code:
<input type="text" name="additionalField" /> 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: PHP Code:
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: PHP 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: PHP Code:
Case study Let's say we want to add an additonal field that will carry the source URL of an article. First we add: HTML Code:
<input type="text" name="additionalFieldURL" /> Then create a plugin (something similar to the following). PHP Code:
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 :) |
Nice Guide, Thanks.
|
what about CMS additional fields?
|
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.
|
great can this be done for individual forum categories? For example not in lobby forum but in forum a b and z etc.
|
Quote:
PHP Code:
PHP Code:
|
thanks alot for your good work
|
very tough to understand. :confused:
|
the bbcode parsing is not working properly i use [CODE] tags and it all shows in one line.
|
Quote:
|
All times are GMT. The time now is 10:52 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|