View Full Version : how to add new fields in post page?
radiofranky
07-23-2011, 07:00 AM
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
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:
$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)
radiofranky
07-25-2011, 04:57 PM
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
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.
how do you pass from "form" to those variables?
thanks for the helps
Sorry, I'm not sure what you're asking.
radiofranky
07-25-2011, 06:51 PM
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
If you add HTML to the template like this:
<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)
$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'].
radiofranky
07-25-2011, 07:23 PM
I will try it out tonight when I go home...
Thanks for all the helps! :)
--------------- Added 1311664092 at 1311664092 ---------------
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
radiofranky
07-27-2011, 02:09 AM
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
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.