The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[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" /> <img id="display_posticon" src="{vb:raw selectedicon.src}" alt="{vb:raw selectedicon.alt}" /> </div> 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 |
#22
|
|||
|
|||
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 |
#23
|
|||
|
|||
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 |
#24
|
|||
|
|||
Hi,
Could you expand a little bit on this article by adding storing those variable to DB and retrieve them for different template? thanks |
#25
|
|||
|
|||
works with the 4.1.5 version, the search mode is enabled?
thanks |
#26
|
|||
|
|||
It doesnt work for me. What i want is literally:
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. |
#27
|
|||
|
|||
It would be nice to see more of a step by step guide... I have no idea where to put all this code...
|
#28
|
||||
|
||||
How to save this data in database instead of post?
Thanks |
#29
|
|||
|
|||
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.
|
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|