The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Creating Custom Promotions & validating profile fields
I new new to VB and have been trying to setup a support form.
My requirement: For each purchase I give user a purchase code which she uses to gain access for the support forum for that respoective product only. What I have dont so far? ->I have created usergroups for each product, where each product forum is accessible to that user group. -> Added profile fields for users to enter purchase code against each product. What I need to do and How can I do this? -> Validate purchase code using my http API on Profile field saving. -> Add additional usergroup to the user's groups if validation is successful. The second one I believe could be done by creating some custom promotion to change the usergroup. Please suggest if you've a better idea to how can I achieve this... |
#2
|
|||
|
|||
Well, since more people could be visiting this thread. The solution is to create a plugin which changes the usergroup based on the profile field. Since CURL is allowed in the plugin one can validate it via and API call. I have partially succeeded in achieving this so will post the whole code once its complete.
cheers, VT |
#3
|
|||
|
|||
have to Admit, very poor documentation to start coding on VB.
To VB guys here's a suggestion: Learn from WordPress on how CODEX should be built to help developers. |
#4
|
|||
|
|||
I agree, it's difficult to get started. I haven't been around that long compared to some here, but I think the reason is that vbulletin wasn't originally designed to support code modifications. The hook system was added later, but it was just a matter of choosing some locations in the code where plugin code can be executed, and there really is no API so you have to read the code to figure out what to do.
Having said that - if you have specific questions you can ask and someone will probably be able to help. |
#5
|
|||
|
|||
Thanks KH99, was hoping someone to reply.
To begin with: I want to know the hook which gets triggered when a user saves her custom profile field. Lets say I created a profile field from adminCp as "A" Now I want to run my code when "A" is saved/updated by the user. |
#6
|
|||
|
|||
OK, well, there are two places it can be changed (the "settings" page and the profile), as well as registration, if you've set it to show up there. But I think you could handle any case by using hook userdata_presave. At that point you can check the value and set an error if it's invalid (or do anything else you want, of course). So basically something like this:
Code:
if ($this->setfields["fieldX"]) // field X has been set, new value in $this->userfield["fieldX"] { if ($this->userfield["fieldX"] is bad) { $this->error('errorphrase'); } } Of course you'd replace X with the id of your field, and errorphrase with the varname of an actual phrase (that you'd need to create). Also note that that plugin is executed inside a function, so if you need global variables you have to use "global". If you want to see what's going on, look at includes/class_dm_user.php, around line 1865, and maybe ajax.php, the 'saveuserfield' section that starts around line 814 to see how the datamanager is used to update profile fields. |
#7
|
|||
|
|||
Thanks a lot,
So I get most of my answers with this hook "userdata_presave" to validate my field via API & "userdata_postsave" to change the usergroup.... --------------- Added [DATE]1354952836[/DATE] at [TIME]1354952836[/TIME] --------------- I more query, How do I set a secondary user group. I can fetch all data of a user using global $vbulletin; get the existing membergroup ids as $vbulletin->userinfo['membergroupids']; now I want update the exisiting member ids. I found this line in forums: $userdata->set('membergroupids',$membergroupids); is $userdata also a global var like $vbulletin? when I try updating the update field is stuck ... is there something Im doing wrong here.. --------------- Added [DATE]1354955672[/DATE] at [TIME]1354955672[/TIME] --------------- That worked.... But now I am stuck at another issue, I used my code for the administrator and it worked, , $userdata->set('membergroupids',$membergroupids); So, now the admin is has addition usergroup, but this did not work for the other sample user I tried... even a simple error message on profile field update is not appearing for the user... any clues? |
#8
|
|||
|
|||
All Right,
Everything is complete now and I've tested that if the profile field is set then add additional member group to user and change its primary group. But now, when I make an api call to validate the data entered in the profile field the user get stuck on loading saving the profile field..... So, I guessed that it might be because of the api call (which is pretty fast)... But what I could not understand is even if I set other field the loading state of the profile field never ends even if it is not field "X" .... need help..please..almost done.. |
#9
|
||||
|
||||
PS: can you give me a demo (PM me)? I dont understand all what you needed, I think I can help you.
I think you can run a query for the user if that user has set userfieldX |
#10
|
|||
|
|||
great,
Below is my plugin code, what it does is as soon as user fills the profile field "X" , it validates it via an API call, if correct then changes the primary usergroup of the user to registered members from novice and adds a membergroup which gives user privelages to access the special forum: PHP Code:
Now the issue is: Whether or not field7 is edited or not. User can not save profile changes as it gets stuck at loading state. My inferences form this: -> So it looks like the code is being executed for all the fields whereas it should execute only when field 7 is saved. -> The wait for save never ends, I dont see an error or save. but when I refersh the page the new value is saved and shown for field7. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|