vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   how to add new fields in post page? (https://vborg.vbsupport.ru/showthread.php?t=267264)

radiofranky 07-23-2011 07:00 AM

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

kh99 07-23-2011 02:36 PM

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)

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

kh99 07-25-2011 05:24 PM

Quote:

Originally Posted by radiofranky (Post 2224844)
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.

radiofranky 07-25-2011 06:51 PM

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

kh99 07-25-2011 07:19 PM

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'].

radiofranky 07-25-2011 07:23 PM

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

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


All times are GMT. The time now is 04:55 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
  • Page Generation 0.01026 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete