News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Custom Profile Fields in Database

Started by AARisAIR, April 07, 2008, 05:15:53 PM

Previous topic - Next topic

AARisAIR

My question is this: where does SMF 2.0 store the data for the custom profile fields in the database. I am asking because I am writing a script to extract the data in the profile and display it on a different page.

Thankyou in advance,
AARisAIR

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

auss9960

I added profile fields without using any mod, but I can't find where the extra data is being stored. I have attached my Profile.template if anyone can find what I need.

It would be useful to me if someone could tell me how to get the data to store in the smf_members table in my database to make things a lot easier, and enable me to recall the data in the members list. I would really appreciate some help.

Oh yes, also my admin save button no longer works, so I must have made a mistake in the coding. If someone can spot why and let me know I'll buy you a beer!

Aus

Kindred

you want to avoid making too many changes to your members table.

As for spotting errors, hard to do without a file or url...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

auss9960


N3RVE

Ralph "[n3rve]" Otowo
Former Marketing Co-ordinator, Simple Machines.
ralph [at] simplemachines [dot] org                       
Quote"Somewhere, something incredible is waiting to be known." - Carl Sagan

karlbenson

The structure/detail of the fields is in {db_prefix}custom_fields

but the actual data submitted the user IS stored in smf_themes.

N3RVE

Ralph "[n3rve]" Otowo
Former Marketing Co-ordinator, Simple Machines.
ralph [at] simplemachines [dot] org                       
Quote"Somewhere, something incredible is waiting to be known." - Carl Sagan

auss9960

Thanks,
            Yes I did find them in the themes database. Can anyone tell me why the account edit submit button has been disabled?

             Also, how would I change the storage table of this data to the smf_members table?

Aus

Kindred

#9
once again, why would you want to change the table to the member table? You should avoid making any unnecesarry changes to the member table, that's why this information is stored in the themes table instead.

And changing it would be fairly involved.

and wow...   what a mess that code is....   why did you add all that junk in when the system automatically does much of that?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

auss9960

Hi Kindred,
                 The simple answer is that it's not that simple. Going by the number of threads I have sifted through over the past few weeks, there are a lot of people having trouble with the Custom Profile Mod, and an equal number of people who can't find their data in their database, or want to add something to their members list. It is quite frustrating adding a module that doesn't apply to a users theme, since almost everyone uses a theme they like.

I followed the instructions in this tutorial: Custom Profile Fields [nofollow] on how to manually add and display custom fields, and it seemed to work exactly at the time, until I found out that my account edit submit button no longer worked. If you want to help out, fine. If not, don't. I'm learning php gradually and solving things mostly myself, but sometimes with guidance from those interested in helping.

Having said all this, I have found a way to add fields to the smf_members database (so that all the relevant info is stored in one location) from the profile, and have included my working notes below. I have also added notes following about how to include this field in the memberlist as well, for anyone who wants to know. It's not all that hard really if you follow the steps carefully. If anyone is grateful for this info, I would still appreciate any help to get my admin edit submit button operational again. See Below:

//ADD new data fields to profile & store the data in smf_members database

<START>

//FIRST you must manually add the column you want to your database

Go to your PHP database in the smf_members table (in structure view)

Scroll down to the bottom and at the end of the field list you will see:

"ADD 1 FIELD(S)" WITH SELECTION BOXES OF WHERE YOU WANT THE FIELD TO APPEAR

Then follow each step below, changing 'test' to whatever name you labelled your field

Repeat as often as necessary for as many fields you want...


//In Sources/Profile.php
//----------------------


<search>$profile_strings = array(</search>

<add your data field:> 'test',</add>

<search>'birth_date' => empty($user_profile[$memID]['birthdate'])</search>

<add>'test' => !isset($user_profile[$memID]['test']) ? '' : $user_profile[$memID]['test'],</add>

<search>// Overwrite member settings with the ones you selected.</search>

<add to array>'test' => !isset($_POST['test']) ? '' : stripslashes($_POST['test']),</add>


//In Sources/Load.php
//-------------------


<search>if ($set == 'normal')</search>

<add your data field:> mem.test [nofollow],</add>

<search>elseif ($set == 'profile')</search>

<add your data field:> mem.test [nofollow],</add>

<search>// What a monstrous array...</search>

<add your data to array:>'test' => &$profile['test'],</add>


//In Themes/default/Profile.template.php
//--------------------------------------

<search>// Left hand profile column - where all the important user info is displayed.</search>

//Locate where you want your new profile item to appear:

<add your new data to display:>// Profile test
   echo   '
            <tr>
               <td><b><font size="2">Test:</font></b></td>
               <td><font size="2">', $context['member']['test'], '</font></td>
            </tr><tr>';</add>

<search>// The main Input Fields for profile</search>

//Again locate where you want your input field to appear

<add your new input field>// Test Input
   echo '
                                <tr>
               <td width="40%"><b>Test: </b></td>
               <td><input type="text" name="test" size="50" value="', $context['member']['test'], '" /></td>
            </tr>';</add>

</END>

//To add any of these new fields to the memberlist:


//In Sources/Memberlist.php
//--------------------------


<search>// Set up the columns...</search>

<add>      ),
                'test' => array(
         'label' => 'Test',
         'width' => '40'

<search>// List out the different sorting methods...</search>

<add>      ),
      'test' => array(
         'down' => 'mem.test ASC',
         'up' => 'mem.test DESC'</add>

<search>// They're searching..</search>

<add>      if (in_array('test', $_POST['fields']))
         $fields += array('test');</add>

//In Themes/default/Memberlist.template.php
//------------------------------------------


<search><td colspan="12"</search> (WHEREVER IT OCCURS, THE NUMBER 12 WILL BE DIFFERENT IF YOU HAVE MORE THAN 12 COLUMNS IN YOUR MEMBERLIST ALREADY)

<change>"12"</change> to the number of columns you need...

<search>// Assuming there are members loop through each one displaying their data.</search>

<add><td class="windowbg2">', $member['test'], '</td></add>

<search>// Display the input boxes for the form.</search>

<add><label for="fields-test"><input type="checkbox" name="fields[]" id="fields-test" value="test" class="check" />Search by Test</label></add>

For notes on how to change the 'test' field from a simple text field see Custom Profile Fields [nofollow].

Sincerely,
              Aus

Kindred

well, for one, you are posting in the SMF 2.0 area.   SMF 2.0 includes custom profile fields as standard and no mod is needed, so it seems that either you wrongly attempted to use a mod that was designed for a previous version and did not look at the standard function or you are posting in the completely wrong area.

for two, as I said, you probably want to stay away from modifying the members table too much. (this is one reason that the CPF does not create new tables in the members table, but rather stores the data in the theme table.

Please note that storing the data there does not prevent it from being used in the memberlist.  As a matter of fact, I saw a mod just yesterday that allows the admin to choose to add CPFs into the memberlist as well as the registration and profiles.

For three...   the instructions on adding additional profile fields were written for the 1.1.x series.  Doing it on 2.0, as listed, with the theme and source files being VERY different, I am not surprised it something got messed up.
Going through the large chunks of code that you added will take time (which I have not had a lot of today)


and lastly, please use the code tags when posting code. especially large chunks like that.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

auss9960

Not to worry, I have fixed it all up myself, thanks. Problem solved, plus I learned something new. A good day all round!

Aus

Advertisement: