[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:
|
Can you show how to add the new value to a separate field in the thread table?
thanks in advance |
what about CMS additional fields?
|
how to add field before username
|
Quote:
--------------- Added [DATE]1283604974[/DATE] at [TIME]1283604974[/TIME] --------------- Quote:
|
Quote:
|
Quote:
|
I need how-to guide for Extra Post Fields similar to extra thread fields written in this article.
Thanks |
How would you use $value = $vbulletin->input->clean_gpc('p', "additionField", TYPE_STR); to get both the value and text from a dropdown list?
Never mind. Figured it out. |
Glad I found this article. Too bad I have yet to figure out what I'm trying to do. Hopefully someone here can help.
I'm trying to add a field in the template "calendar_edit" for people to add an image url to calendar events. I got the field visible when creating an event by using the following: Code:
<div class="blockrow"> Eventually, I want to place this image in a sideblock for upcoming events but it's not saving the field entered data. --------------- Added [DATE]1290186736[/DATE] at [TIME]1290186736[/TIME] --------------- Here is the product I have edited. PHP Code:
Does everything else look right? Do I need this for what I'm trying to accomplish?: PHP Code:
And here is my Forum Block: PHP Code:
|
How do i save it as separate column in post or thread table instead of modifying post message? It could be much more useful i think.
|
Thanks for the tutorial. Can this be expand to create an additional "prefix" field?
1st prefix ==> [laptop] my thread title - free shipping <= additional prefix Thanks |
Looked at the thread and I must say its been very informative. Thanks for writing this up.
For my need I have added a custom field called "customID" into thread and post table and my objective is to write this field to thread and post table for new threads. My understanding is this that when we add new thread, logic writes one record in thread table and also in post table. Any insight regarding that would be greatly appreciated :) |
Hi,
Could you expand a little bit on this article by adding storing those variable to DB and retrieve them for different template? thanks |
works with the 4.1.5 version, the search mode is enabled?
thanks |
1 Attachment(s)
It doesnt work for me. What i want is literally:
https://vborg.vbsupport.ru/attachmen...1&d=1327779094 https://vborg.vbsupport.ru/attachmen...1&d=1327779636 So i dont know really what i gotta do. In postbit before $post[message] as picture above code is: <table> <tr> <td> <img src="$picture" /> </td> <td></td> ... </tr> </table> I dont want to add it to the extra database table so it must come with $custom_message; but when it comes here how can i seperate picture url, how can i write table code above.. Thanks for your reply. |
It would be nice to see more of a step by step guide... I have no idea where to put all this code...
|
How to save this data in database instead of post?
Thanks |
Works great on 3.8.5, thanks so much! So simple yet I've been looking for something like this for years and had trouble with the forms plugins I could find.
|
All times are GMT. The time now is 10:51 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:
|