Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[HOW TO] Add custom fields to new threads
jaybolt
Join Date: Jun 2004
Posts: 20

 

UK
Show Printable Version Email this Page Subscription
jaybolt jaybolt is offline 04-26-2006, 10:00 PM

Ok - this is my first submitted 'how to' and is the result of me wanting to add a couple of new fields to my new threads. A quick search on here showed me a couple of people asking the same but no conclusive answers (there were a couple of threads with 'typos') so here is my code as is. It works for me anyway!

1. To add the fields to the thread table in the database:

Go into admincp and down to the bottom. Select Execute SQL Query and then add your fields as follows:

Code:
ALTER TABLE table ADD (
         var VARCHAR(10) not null default ''
)
Where table is the name of your vb thread table (eg vb_thread) and var is the name of the field you are adding.

2. Add the fields to the newthread template in admincp / style manager

Find
Code:
<if condition="$show['misc_options']">
and above that add:

Code:
<div style="padding:$stylevar[formspacer]px">
<div>
<input type="text" class="bginput" size="10" name="var" value="" id="var" tabindex="1" /> $vbphrase[var_name]</div>
Again, var is the name of the field and the same as in the previous SQL Query. You can smarten this up further using the fieldset tags and creating a custom vbphrase for the $vbphrase[your_phrase] part :

Code:
<fieldset class="fieldset">
<legend>$vbphrase[your_phrase]</legend>

above code in here

</fieldset>
3. Go to admincp / add new plug in and add the following three plugins (give them the same name so you recognise them later):

newpost_process

Code:
if ($type == 'thread')
{
    $dataman->setr('var', $post['var']);
}
newthread_post_start

Code:
$vbulletin->input->clean_array_gpc('p', array('var' => TYPE_STR));

$newpost['var'] =& $vbulletin->GPC['var'];
threadfpdata_start

Code:
$this->validfields['var'] = array(TYPE_STR, REQ_NO);
Once again, var is the name of the variable you have been using for your field name above.

I hope this helps - took me a while to get it sorted (and I did find help on here along the way) but this is the completed process.

[EDITED: corrected an inevitable type in the SQL query ]
Reply With Quote
  #12  
Old 10-26-2007, 10:43 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by FatalBreeze View Post
that's a great article!
But if i want to edit my newthread? and then change the value of 'var', how do i do it?
I'd like to know that also..

solution is in threadadmin_update ....
Reply With Quote
  #13  
Old 11-02-2007, 09:01 PM
brandondrury brandondrury is offline
 
Join Date: Oct 2005
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
great article but its not inserting any data into the database using vb3.6.8 ? any ideas.
Same here.

Brandon
Reply With Quote
  #14  
Old 11-04-2007, 02:34 PM
fly fly is offline
 
Join Date: Oct 2003
Posts: 1,215
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Shouldn't you be using 'set' rather than 'setr'? I remember Andreas telling me not to use setr, as it bypasses some vB checks. I'm no genius at the stuff, so please excuse me if I'm wrong.
Reply With Quote
  #15  
Old 11-08-2007, 08:04 AM
Jelmertjee Jelmertjee is offline
 
Join Date: Oct 2006
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it's working fine for me (tested on clean 3.6.8 pl2 install) although you need to do more edits to actually show the $var in the thread, it does get inserted into the database for sure. If it's not working make sure you have used the right table name.. and the same $var everywhere.. Thanks for the article jaybolt.

so, how would you use it in a thread?

change a query in showthread.php and select the var, then put the $var into your showthread template wherever you want it.
Reply With Quote
  #16  
Old 11-08-2007, 08:12 AM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did not have to do any additional edits on 3.68 patch level 2
Reply With Quote
  #17  
Old 11-12-2007, 06:05 PM
Jelmertjee Jelmertjee is offline
 
Join Date: Oct 2006
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so do you mean the "$var" was automatically added to the thread, without any edits, I guess you would need to change the template at least, and thought you would need to do more programming?!

So did anyone manage to implement this with the ability to edit threads as well? besides just creating them, like this is not very useful, often you just want to make some changes if you spot a mistake somewhere.. at least I do.
Reply With Quote
  #18  
Old 12-17-2007, 04:47 PM
wolfe wolfe is offline
 
Join Date: Jan 2002
Posts: 900
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how do i make it so i can edit the fields and update them because currently its updating blank fields
Reply With Quote
  #19  
Old 02-13-2008, 10:08 AM
Lott Lott is offline
 
Join Date: Mar 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm also having difficulties inserting any data into the database using vb3.6.8.

Is there a specific "Hook_Location" that should be used for the plugins. I've tried "admin_index_main1", which was the default and "threaddata_postsave" - neither of which work.

Thanks for your help.
Reply With Quote
  #20  
Old 02-13-2008, 12:46 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lott View Post
Is there a specific "Hook_Location" that should be used for the plugins.
Did you try the words given in bold above the piece of code?...

(in the original post.)
Reply With Quote
  #21  
Old 02-14-2008, 12:08 PM
Lott Lott is offline
 
Join Date: Mar 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Opserty View Post
Did you try the words given in bold above the piece of code?...

(in the original post.)
Oops! - no I used these as the names of the plugin!
It seems obvious when you know how!

I used the bold words now and it works.

Thanks
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 03:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07017 seconds
  • Memory Usage 2,305KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (3)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete