View Single Post
  #5  
Old 09-26-2001, 06:31 AM
Admin's Avatar
Admin Admin is offline
Administrator
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
(But of course change {secondaltcolor} to {firstaltcolor}, depends on where you put this, what's before, what's after, etc.)

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:
// ############################### start modify profile ###############################
if ($action=="editprofile") {
  ...
  ...
  ...
  eval(
"dooutput(\"".gettemplate("modifyprofile")."\");");

So we're gonna add this:
PHP Code:
  if ($bbuserinfo[sex]) {
    
$sexsel[$bbuserinfo[sex]]="selected";
  } else {
    
$sexsel[dunno]="selected";
  } 
right after this:
PHP Code:
  if ($allowsmilies) {
    
$smiliesonoff=$ontext;
  } else {
    
$smiliesonoff=$offtext;
  } 
(the IF is just in case the field is empty when the user changes his profile. Not really necessary, but we all like things organized()
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
I went for 8 since in this case the max value that can be is 'female' (6).

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]'");
So let's add this to the query:
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]'");
This will insert $sex ('dunno', 'male' or 'female') into the sex field in the user table.

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)
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01261 seconds
  • Memory Usage 1,806KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete