The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
I'd like to be able to make a custom profile field a drop down menu or button select instead of just a text input. There are certain fields that I need to restrict my users to only a select few choices. In UBB, every extra field was manually added through hacks, but vB creates them automatically. While this saves a lot of time, it also leaves me with less control.
An example of this would be using "Gender" as a custom field, and only having 'male' or 'female' as selectable choices, so they couldn't type in "transsexual" or something. I have a few fields that I'd need a pull down menu for. How would I set that up? (It seems like every time I post a "How Do I" question, I get the feeling it belongs in the hack request forum, but I'm not really sure) |
#2
|
||||
|
||||
You have no less control with our system. You can hack the user table and add all the fields you want and the accompanying html/php to support it. Just look how the www or icq fields are handled.
Expanding the field types is on the todo list though. |
#3
|
||||
|
||||
Quote:
PHP Code:
|
#4
|
||||
|
||||
i guess what I'm asking is.. how do I pull a custom field value directly from the database, just like the default fields (aim, icq, www, birthday, etc.)?? I want to be able to plug in custom field values anywhere I want, instead of $customfields doing my dirty work for me. This would really help me create my registration, edit profile, and view profile pages.
Any (specific) tips would be appreciated |
#5
|
||||
|
||||
So you want a drop down field right?
Alrighty. Part 1 First of all we will take care of the modifyprofile template. In there, add something like this: Code:
<tr> <td bgcolor="{secondaltcolor}"><normalfont><b>Are you a male of a female?</b></normalfont></td> <td bgcolor="{secondaltcolor}"><smallfont> <select name="sex"> <option value="dunno" $sexsel[dunno]>I don't know yet.</option> <option value="male" $sexsel[male]>Male.</option> <option value="female" $sexsel[female]>Female.</option> </select></smallfont></td> </tr> See the $sexsel[xxx] variable I put in each option? This is so that when a use comes back to the profile page, what he selected before will show up selected on this page. So he won't have to change this value every time he changes his profile. The $sexsel[xxx] (sex+selected) is set in the member.php page. Where? Somewhere in this block: PHP Code:
PHP Code:
PHP Code:
What will this do? $bbuserinfo[sex] is what the user currently has in his profile for the sex field. So, if he has selected 'male' before, $sexsel[male] will contain the word "selected". So when we put this in the <option> tag, it will cause that and only that option to be selected. Note that the $sexsel[xxx] MUST match the value="xxx", or it just won't work. Ok, so we took care of the end user stuff. But how are we gonna insert this info into the database? Part 2 So first of all, we need to create the field for that, in the user table. For this example, we'll run this query: Code:
ALTER TABLE user ADD sex VARCHAR(8) not null So, we need to add something to the query that updates the user profile, right? This is the query, as it is now: Code:
$DB_site->query("UPDATE user SET birthday='".addslashes($birthday)."',signature='".addslashes($signature)."',customtitle='$customtitle',usertitle='".addslashes($customtext)."',email='".addslashes(htmlspecialchars($email))."',parentemail='".addslashes(htmlspecialchars($parentemail))."',coppauser='$coppauser',homepage='".addslashes(htmlspecialchars($homepage))."',icq='".addslashes(htmlspecialchars($icq))."',aim='".addslashes(htmlspecialchars($aim))."',yahoo='".addslashes(htmlspecialchars($yahoo))."',usergroupid='$bbuserinfo[usergroupid]' WHERE userid='$bbuserinfo[userid]'"); Code:
$DB_site->query("UPDATE user SET birthday='".addslashes($birthday)."',signature='".addslashes($signature)."',customtitle='$customtitle',usertitle='".addslashes($customtext)."',email='".addslashes(htmlspecialchars($email))."',parentemail='".addslashes(htmlspecialchars($parentemail))."',coppauser='$coppauser',homepage='".addslashes(htmlspecialchars($homepage))."',icq='".addslashes(htmlspecialchars($icq))."',aim='".addslashes(htmlspecialchars($aim))."',yahoo='".addslashes(htmlspecialchars($yahoo))."',usergroupid='$bbuserinfo[usergroupid]',sex='".addslashes($sex)."' WHERE userid='$bbuserinfo[userid]'"); Part 3 Now, let's take care of the registration process. This is optional. You need to decide whether you want to include this when people register, or not. Your choice. If you do want this, tell me and I'll explain this as well. I hope you understand everything. If you still got questions, just ask. (sorry about the width of this. Long queries, you know :P) |
#6
|
|||
|
|||
call me crazy, but isnt there a method of just hardcoding the drop down option in the main profile script? If I remember correctly, there was some hack here awhile back that allowed a person to add the option of choosing either a text field, drop down..etc..to the custom profile fields...Not that your way wont work firefly, it is just that I could of swore i added a drop down hack for user profiles onto our site at one time...worked slick, but lost it when i upgraded...
|
#7
|
||||
|
||||
I think I know what you mean.
I'll find the thread in a sec. http://www.vbulletin.com/forum/showt...threadid=21833 But I remember that it uses flat files, which kinda sucks (IMO). This is exactly how it's done with the other drop-down fields in vBulletin. I dunno, but for me it looks like the easiest, cleanest way to do this. I know it requires a bit hacking, but not TOO much of it. Maybe a hack can be written to do this automatically... |
#8
|
|||
|
|||
ah yes...thats rite...I had a +++++ of a time getting that one to work come to think of it..
|
#9
|
||||
|
||||
Quote:
thanks for explaining this all. 2 questions though... 1) If I add this to my vB now, it wouldn't cause problems when I import users from UBB, would it? 2) Why do I need to add the extra field from the database, instead of the control panel? Is that using a totally seperate table from the other custom fields? |
#10
|
||||
|
||||
1) I really can't tell, sorry. I'm not familiar with UBB, at all, and neither with the importer.
But still, I don't think you should have any problems. The field will just be blank. I dunno, sorry. 2) First of all, when you add a field from the contorl panel, it still adds it to the database. And if you add it from the control panel, it would be: - a) in a different table. - b) it will automatically show up with the rest of the custom fields, scuh as location, biography, etc. I'll work on part 3. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|