I've added some custom fields to the profiles template and everything works well. But I was wondering how difficult it would be to write the data to the smf_members table instead of the smf_themes table. I can't figure out how many files I would need to modify.
I'm asking this because I want to add a considerable amount of custom fields and I think it would be easier to export and analyse the data if it was added in the members table.
To give an example:
I've added a field "occupation" to the profiles. I've added a column 'occupation" to the smf_members table. But how difficult would it be to write and read the data to and from the smf_members table?
There are topics about this. You mainly have to edit Profile.php.
-[Unknown]
I've read allot of topics about custom fields and found one (http://www.simplemachines.org/community/index.php?topic=11662.0) discussing the option of writing the data to the members table. But, unfortunately, it doesn't say what should be modified to make this work. So that's why I asked.
What I've got working so far is an extra field in the profile that (that was easy of course) and the data is written to the smf_members table (I thought that this would be the hard part), but I can't get the data to show in the profile. No errors whatsoever.
This is the code I have added to Profile.template.php:
<tr>
<td width="40%"><b>Zipcode:</td>
<td><input type="text" name="zipcode" size="50" value="', $context['member']['zipcode'], '" /></td>
</tr>';
Why isn't the data shown in the input-box?
Here's the code I've added to Profile.php:
added zipcode to line 436:
'location', 'zipcode', 'birthdate',
inserted the following line on line 1338:
'zipcode' => !isset($user_profile[$memID]['zipcode']) ? '' : $user_profile[$memID]['zipcode'],
inserted the following line on line 1788:
'zipcode' => !isset($_POST['zipcode']) ? '' : stripslashes($_POST['zipcode']),
I'm a little concerned about the word 'mainly' in your reply, what other files should I have a look at?
Load.php (loadMemberData() and loadMemberContext()) is the only other file, really.
-[Unknown]
Indeed, I added mem.zipcode to $select_columns = "..." (twice, for "if" and "elseif")
and 'zipcode' => &$profile['zipcode'], to the $themeUser[$user] array.
And it seems to work just fine. Still have to test it some more. But thanks allot for the help!
P.S. Maybe a little offtopic, but I was wondering: why is location being fetched twice from the members table. Maybe it's me, but I see mem.location twice in the variable $select_columns = "..."
Hi,
I'm also adding new fields. But i would like to use a drop down menu to select different kinds of stuff. I'm not entirely sure how i should write in the "function rememberPostData()" and the "function forumProfile($memID)".
I made a drop down menu like this in "Profile.template.php"
<td width="40%"><b>Race: </b><div class="smalltext">Your characters race.</div></td>
<td>
<select name="char_race" size="1">
<option value="0"></option>
<option value="1"', ($context['member']['char_race']['name'] == 'Human' ? ' selected="selected"' : ''), '>Human</option>
<option value="2"', ($context['member']['char_race']['name'] == 'Night Elf' ? ' selected="selected"' : ''), '>Night Elf</option>
<option value="3"', ($context['member']['char_race']['name'] == 'Gnome' ? ' selected="selected"' : ''), '>Gnome</option>
<option value="4"', ($context['member']['char_race']['name'] == 'Dwarf' ? ' selected="selected"' : ''), '>Dwarf</option>
<option value="5"', ($context['member']['char_race']['name'] == 'Orc' ? ' selected="selected"' : ''), '>Orc</option>
<option value="6"', ($context['member']['char_race']['name'] == 'Troll' ? ' selected="selected"' : ''), '>Troll</option>
<option value="7"', ($context['member']['char_race']['name'] == 'Tauren' ? ' selected="selected"' : ''), '>Tauren</option>
<option value="8"', ($context['member']['char_race']['name'] == 'Undead' ? ' selected="selected"' : ''), '>Undead</option>
</select>
</td>
I took a peek at how "gender" is beeing posted but it didn't help much, my php skills are still quite limited.
Best Regards
It's the same thing as far as $_POST['char_race']. Just because it's a drop down doesn't mean it's any different, really, from a string.
-[Unknown]
Ok, thx for the help m8, i'll start working on it asap :)