View Full Version : adding another parameter when posting
emath
11-18-2009, 09:49 AM
ive an help forum, which helps students to solve problems from a books.
and i want to collect all these solutions into one table so i could do a search in that table and find a specific solution easy.
im trying to add some more parameters(actually 3) to a specific group when they are posting .
like there is the "title:" parameter, so i want to add there also "book name: " , "page number : " , "exercist number : "
i succeed to add the parameters next to the "title:" and the textbox,
but i just dont know how to add the data to vbulletin database , or how to create the table for it, i need to do it manually ?
please help me.
regards,
Lynne
11-18-2009, 01:50 PM
If you need a new table, then you are going to have to create it manually. Then you will have to write the code to insert your data into the table.
emath
11-18-2009, 06:57 PM
yes ive created the table i wanted , but where do i write the code to inesrt the data i wrote above into the table ??
for e.g , where is the code which inserts the "title" thread name into the right table .. ?
Lynne
11-18-2009, 07:03 PM
I don't know where you would add it. What is it based on - stuff they insert into a new thread? If so, look at the newthread template for a good hook location to plugin to.
emath
11-18-2009, 09:33 PM
i want to know where the code that they add the newthread information into the database ??
or where the code that they add the newpost information into the database ??
there isnt such code like "insert into" or "$db" in newthread nor newreply...
Lynne
11-18-2009, 10:40 PM
check out the function build_new_post in includes/functions_newpost.php . That is where a new post gets created.
emath
11-19-2009, 05:31 AM
ok thanks i can see that, i looked over the code and found the "build_new_post" function.
though i still cant understand how to do what i wanted.
next to the title : textbox ive added bookname:textbox .
now i want to insert the text in the bookname textbox into the table ive created (vb_Solutions) .
how can i do it ?
where is the code that acutally adds the title information into the database ? so ill see an e.g ...
regards,
Lynne
11-19-2009, 01:51 PM
You'll want to use the datamangers there. You can read up on datamanagers in the articles forum. Basically, first you need to add the fields to the $validfields array (again, search the files to find it - hint, check the beginning of vB_DataManager_Thread for a hook - threaddata_start), and then you will have to set each of the fields prior to them being saved in the datamanager.
I would strongly suggest finding some modification here that is similar to what you want and looking to see how they did this.
emath
11-19-2009, 02:16 PM
ive looked weeks for a mod that will fit to me, but found nothing.
anyway thanks alot for the help...
it did help me.
if u know a mod that could help me then ill be glad to hear..
Lynne
11-19-2009, 03:31 PM
I think the Thank You mod adds a field to a thread and then writes to it at times. Just find a mod that does similar things as yours, like that one, and see how they added their field to the $validfields array. I'm not saying to use their mod, just look at what they did and the hooks they used.
emath
11-19-2009, 03:41 PM
thanks alot !!
--------------- Added 1258717639 at 1258717639 ---------------
in newreply.php (i think this is the file i need to edit)
they have the part :
$globaltemplates = array(
'newreply',
'newpost_attachment',
'newreply_reviewbit',
'newreply_reviewbit_ignore',
'newreply_reviewbit_ignore_global',
'newpost_attachmentbit',
'im_aim',
'im_icq',
'im_msn',
'im_yahoo',
'im_skype',
'postbit',
'postbit_wrapper',
'postbit_attachment',
'postbit_attachmentimage',
'postbit_attachmentthumbnail',
'postbit_attachmentmoderated',
'postbit_ip',
'postbit_onlinestatus',
'postbit_reputation',
'bbcode_code',
'bbcode_html',
'bbcode_php',
'bbcode_quote',
'humanverify',
);
is this the $validfields u meant ?
--------------- Added 1258719365 at 1258719365 ---------------
Lynne
11-20-2009, 01:29 PM
No, those are templates. You should try an actual search through the templates for $validfields and you would find it. The thread one is in class_dm_threadpost.php in the datamanager. The next hook after the fields are defined is threaddata_start, as I said before, and so you can plugin to there and add to the array.
emath
11-20-2009, 03:25 PM
ok ive looked in the file u mentioned ("class_dm_threadpost.php") and ive there three classes that have this $validfields array .
i have added in the following textbox in the template "newreply" :
<td><input type="text" class="bginput" name="bookname" value="$bookname" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
<td><input type="text" class="bginput" name="pagenumber" value="$pagenumber" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
<td><input type="text" class="bginput" name="exnumber" value="$exnumber" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
so in each class on the file class_dm_threadpost.php i need to add to the $validfields array things like :
'bookname' => array(TYPE_STR, REQ_NO),
'pagenumber' => array(TYPE_STR, REQ_NO),
'exnumber' => array(TYPE_STR, REQ_NO)
by the same order,
and then what? where they will be available? sry im so annoying about this.. but belive me im reading alot about these datamanager and still havent understood how the all proccess goes .
ill be glad if u could more specific.
in addition, where shall i look for more "$validfields", in what templates? not through the admin cp right ? cause there i found nothing .
and so, i didnt understand what shall i do with the : threaddata_start .
the code i found about this hook is :
function vB_DataManager_Thread(&$registry, $errtype = ERRTYPE_STANDARD)
{
parent::vB_DataManager_ThreadPost($registry, $errtype);
($hook = vBulletinHook::fetch_hook('threaddata_start')) ? eval($hook) : false;
}
in the same file u mentioned.
regards,
Lynne
11-20-2009, 03:39 PM
When you add them to the validfields array, you may then use the datamanager to 'set' them prior to saving them. So, in threaddata_start, you add them:
$this->validfields['whatever'] = array(TYPE_UINT, REQ_NO);
And then in your plugin, you set them:
$threadman->set('whatever', $vbulletin->GPC['whatever']);
You would do that prior to them being saved:
$threadman->save();
Did you do as I suggested and look at other modifications to see how they do this?
emath
11-20-2009, 04:34 PM
yes i did that and also looked in "product-thread_thumbnails_v2" which adds another parameter to the thread(picture) and searched for "validfields" but found nothing.
in the file class_dm_threadpost.php there is three functions which using the validfields array, i need to add fields just to the class vB_DataManager_Post or to all of them ?
"in threaddata_start, you add them" where is the threaddata_start ?
in the function i posted above ?
and i have no plugin, what does it mean in my plugin ? in what file ? newreply.php ?
isnt some guides for this ? i read alot at the articles but still cant figure out...
Lynne
11-20-2009, 04:51 PM
You might want to read this section in the manual - Plugin System (http://www.vbulletin.com/docs/html/plugin_system)
emath
11-20-2009, 05:05 PM
ok im reading this, can u please answer my questions ?
--------------- Added 1258745069 at 1258745069 ---------------
ok so i understood i need to do add a plugin and there to choose the threaddata_start hook and there to write the code u said before, and which product i need to choose ?
Lynne
11-20-2009, 05:30 PM
You need to create your own product as that is what you are doing.
emath
11-20-2009, 05:51 PM
ok so let me get it straight :
i go to default style choosing the newreply template, there ive added three textbox next to the title by the code :
<td><input type="text" class="bginput" name="bookname" value="$bookname" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
<td><input type="text" class="bginput" name="pagenumber" value="$pagenumber" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
<td><input type="text" class="bginput" name="exnumber" value="$exnumber" size="20" maxlength="$vboptions[titlemaxchars]" tabindex="1" title="$vbphrase[optional]" /></td>
<td> </td>
<td><img id="display_posticon" src="$selectedicon[src]" alt="$selectedicon[alt]" /></td>
then i go to the file "class_dm_threadpost.php" and in the class vB_DataManager_Post ive the $validfields array i added there :
'bookname' => array(TYPE_STR, REQ_NO),
'pagenumber' => array(TYPE_STR, REQ_NO),
'exnumber' => array(TYPE_STR, REQ_NO)
now i go and creating a product in admin cp.
then creating a plugin, on the plugin choosing the product i just made and in the hook i choose "threaddata_start" .
in the Plugin PHP Code i write :
$this->validfields['whatever'] = array(TYPE_UINT, REQ_NO);
and $threadman->set('whatever', $vbulletin->GPC['whatever']);
and then i save it with : $threadman->save();
but where my table ive created for this goes in all this story ?
and please refer to every step here im rly trying.. and sure that not all is right .
regards,
Lynne
11-20-2009, 05:58 PM
You do not need to edit the file class_dm_threadpost.php to add those validfields if you created the plugin at threaddata_start to add the three fields (by replacing "whatever" with the name of the field, of course).
And you would not save the field using that same plugin. You need to pick a more appropriate hook location which is why I suggested looking at other modifications to see which hook locations they were using.
emath
11-21-2009, 06:45 AM
these are the hooks which thank_you mod use :
cache_templates
userdata_delete
showpost_complete
showthread_complete
template_groups
threaddata_delete
postdata_delete
postbit_display_start
postbit_display_complete
global_setup_complete
member_profileblock_fetch_unwrapped
userdata_update_username
in which one shall i put in the $validvariables my fields ?
and again ,
where my table ive created for this goes in all this story ?
thanks,
Lynne
11-21-2009, 02:35 PM
It seems to me that perhaps your first mod should have been a bit easier. This isn't going to be an easy one and I can't give you all the answers here. All I can do it point you in the general direction.
You need to add all your variables to the $validfields array. I believe I said to do that in threaddata_start and I think I gave an example on that last page.
After that, you need to 'set' that fields after you have the data (from your form) and before they are saved. I can't tell you want hook location to use - you will have to find that by seeing which hooks are available and reading the code to see which is positioned where you want it.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.