Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2011, 07:00 AM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how to add new fields in post page?

hi,
i was wondering how to add additional input fields during thread posting which allow user to fill those input fields? then store into variables and could be used for example add the variable values to thread title

thread title + variables

variable 1 = 100 <= input by the user
variable 2 = 200 <= input by the user
and calculate variable 3 = 100/200 = 0.5 based on the inputs, calculate the third value

and in the final thread title will show something like this.
30 foot sail boat sale for $100, 50% off from it's original price

thanks
Reply With Quote
  #2  
Old 07-23-2011, 02:36 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should just be able to edit the newthread template and put in the new fields where you want them, just make sure they're inside the <form> tags. Then create a plugin using hook newthread_post_start and do something like:

PHP Code:
         $vbulletin->input->clean_array_gpc('p', array(
              
'saleprice'         => TYPE_NOHTML,
              
'price'          => TYPE_NOHTML));

         
$pct intval(($vbulletin->GPC['saleprice']  / $vbulletin->GPC['price']) * 100);
         
$vbulletin->GPC['subject'] .= " for " $vbulletin->GPC['saleprice'] . ", {$pct}% off"

(BTW, I haven't actually tried any of this code)
Reply With Quote
  #3  
Old 07-25-2011, 04:57 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. Could you explain to me a little bit more on the 2nd part? "create a plugin using hook"
I'm new to vb.

how do you pass from "form" to those variables?
thanks for the helps
Reply With Quote
  #4  
Old 07-25-2011, 05:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by radiofranky View Post
Thanks. Could you explain to me a little bit more on the 2nd part? "create a plugin using hook"
I'm new to vb.
- In the admin control panel, go to Plugins & Products -> Add New Plugin
- In the Hook Location drop-down menu, choose newthread_post_start
- Enter a title so that later you'll remember what this plugin does
- Enter the code in the big text area
- Select the "Yes" radio button next to "Plugin is Active"
- Press "Save"

If you want to change it, go to Plugins & Products -> Plugin Manager and click on Edit next to the plugin you want to change. You can also disable it from that page.


Quote:
how do you pass from "form" to those variables?
thanks for the helps
Sorry, I'm not sure what you're asking.
Reply With Quote
  #5  
Old 07-25-2011, 06:51 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
how do you pass from "form" to those variables?
thanks for the helps
You have mentioned to insert input fields in the form and how do I store those input fields into "sale price" and "price"?

thanks
Reply With Quote
  #6  
Old 07-25-2011, 07:19 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you add HTML to the template like this:

HTML Code:
<input type="text" name="price" value="{vb:raw price}">
<input type="text" name="saleprice" value="{vb:raw saleprice}">
When the form is submitted, the values will be in $_POST and you can get them from there, make sure they are of the expected type, and put them in their own variables using code like this (in a plugin like we discussed above)

PHP Code:
              $vbulletin->input->clean_array_gpc('p', array( 
              
'saleprice'         => TYPE_NOHTML
              
'price'          => TYPE_NOHTML)); 
              
$price $vbulletin->GPC['price'];
              
$saleprice $vbulletin->GPC['saleprice'];
              
vB_Template::preRegister('newthread', array('price' => $price'saleprice' => $saleprice)); 
(note that you can change TYPE_NOHTML to some other type if you want, for instance TYPE_UINT if you want to force them to be unsigned integers).

After that (in the same plugin) you can do whatever you want with $saleprice and $price. If you want to modify the title at that point, you can change $vbulletin->GPC['subject'].
Reply With Quote
  #7  
Old 07-25-2011, 07:23 PM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I will try it out tonight when I go home...

Thanks for all the helps!

--------------- Added [DATE]1311664092[/DATE] at [TIME]1311664092[/TIME] ---------------

you're the man!!!! It's work beautifully.

one more question, what are the "TYPE" options do we have?

for example, if someone enter 99.99 and 30, the discount should be 33.33%

should I use "double" instead of integer?

thanks


update: i figured it out. Thanks
Reply With Quote
  #8  
Old 07-27-2011, 02:09 AM
radiofranky radiofranky is offline
 
Join Date: Jun 2011
Posts: 149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

one more question. What should I do if I want display those "variables" in one of the vbadvanced templates? Should I just change the hook file point to vbadvanced template and create another plugin with the same variable setting?

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 12:24 PM.


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.04352 seconds
  • Memory Usage 2,245KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (2)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_postinfo_query
  • fetch_postinfo
  • 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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete