News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Custom Registration and Profile fields

Started by Aravot, March 06, 2005, 06:23:50 PM

Previous topic - Next topic

Aravot

I followed this tutorial, http://unknown.network32.net/tutorial.smf_custom-profile and created two custom registration fields (First Name & Last Name), the inputted info would also show in user "Profile", I created the same custom text fields (First Name & Last Name) in "Forum Profile Information" to unable my current member to write their Name and Last Name.

Everything works fine, but have two question.

Q1. I want to make the two created fields (First Name & Last Name) mandatory during registration, how can I achieve that, any help is appreciated, below is the code

Registration.template.php

</tr><tr>
<td width="40%">
<b>First Name:</b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td>
<input type="text" name="default_options[text_first_name]" size="20" value="', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '','"/>
</td>
<tr>
</tr><tr>
<td width="40%">
<b>Last Name:</b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td>
<input type="text" name="default_options[text_last_name]" size="20" value="', isset($context['member']['options']['text_last_name']) ? $context['member']['options']['text_last_name'] : '','"/>



Profile.template.php - dispaly Name & Last Name

</tr><tr>
<td><b>First Name: </b></td>
<td>', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '', '</td>
</tr><tr>
<td><b>Last Name: </b></td>
<td>', isset($context['member']['options']['text_last_name']) ? $context['member']['options']['text_last_name'] : '', '</td>


Profile.template.php - input box for Name & Last Name

</tr><tr>
<td width="40%"><b>First Name: </b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td><input type="text" name="default_options[text_first_name]" size="50" value="',isset($context['member']['options']['text_first_name'])? $context['member']['options']['text_first_name'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>Last Name: </b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td><input type="text" name="default_options[text_last_name]" size="50" value="',isset($context['member']['options']['text_last_name'])? $context['member']['options']['text_last_name'] : '', '" /></td>


Q2. what part does InstantMessage.template.php effect I added the code from the tutorial but couldn't find any difference from before adding the code.

Here is the site www.peterosipof.com/smf it's a test site so you can create account if you want
.

Louis

ad Q.1:
have a look here and adapt it to your needs: http://www.simplemachines.org/community/index.php?topic=11249

and if you found out where these values are stored in the DB, let me know
It is your mind that creates this world (Buddha)

Aravot

Ok, followed the link read all the topics, but still can't get it to work below is the code, what am I missing.

Register.php

Tried this no go
if (!isset($_POST['options']['text_first_name']) || $_POST['options']['text_first_name'] == '')
fatal_error('Please enter in your name to register.', false);


Tried this same result
if (!isset($_POST['text_first_name']) || $_POST['text_first_name'] == '')
fatal_error('Please enter your name to register.', false);

Louis

Pure guessing (as I don't have the time to test it right now):

Change Register.template.php from<input type="text" name="default_options[text_first_name]" size="20" value="', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '','"/>
to <input type="text" name="options[text_first_name]" size="20" />

and then use $_POST['options']['text_first_name']

BTW: The values are stored in the themes table as user-specific values (don't forget to check if they are stored at all)
It is your mind that creates this world (Buddha)

Aravot

Thanks Louis that worked.

My final code for custom registration with option in profile for current user to add the information, please do check and let me know if they are any errors before I implement it into my main website.

Registration.template.php

</tr><tr>
<td width="40%">
<b>First Name:</b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
         <td>
<input type="text" name="default_options[text_first_name]" size="20" />
</td>
<tr>
</tr><tr>
<td width="40%">
<b>Last Name:</b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td>
<input type="text" name="default_options[text_last_name]" size="20" />
</td>
<tr>


Profile.template.php - display Name & Last Name

</tr><tr>
      <td><b>First Name: </b></td>
          <td>', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '', '</td>
</tr><tr>
     <td><b>Last Name: </b></td>
          <td>', isset($context['member']['options']['text_last_name']) ? $context['member']['options']['text_last_name'] : '', '</td>


Profile.template.php - input box for Name & Last Name

</tr><tr>
        <td width="40%"><b>First Name: </b>
<div class="smalltext">', 'Birth name, Given name', '</div>
        </td>
<td><input type="text" name="default_options[text_first_name]" size="50" value="',isset($context['member']['options']['text_first_name'])? $context['member']['options']['text_first_name'] : '', '" /></td>
</tr><tr>
         <td width="40%"><b>Last Name: </b>
<div class="smalltext">', 'Surname, Family name', '</div>
         </td>
<td><input type="text" name="default_options[text_last_name]" size="50" value="',isset($context['member']['options']['text_last_name'])? $context['member']['options']['text_last_name'] : '', '" /></td>


source/Register.php
// If you're an admin, you're special ;).
if (!$user_info['is_admin'])
{

if (!isset($_POST['options']['text_first_name']) || $_POST['options']['text_first_name'] == '')
fatal_error('Please enter your name to register.', false);

if (!isset($_POST['options']['text_last_name']) || $_POST['options']['text_last_name'] == '')
fatal_error('Please enter your lastname to register.', false);


Aravot


[Unknown]

Quote from: Aravot on March 08, 2005, 03:17:25 PM
Registration.template.php

Register.template.php

Quote

</tr><tr>
<td width="40%">
<b>First Name:</b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
         <td>
<input type="text" name="default_options[text_first_name]" size="20" />
</td>
<tr>
</tr><tr>
<td width="40%">
<b>Last Name:</b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td>
<input type="text" name="default_options[text_last_name]" size="20" />
</td>
<tr>

You're using default_options here still.  That's fine, but if you use it here...

Quotesource/Register.php

Sources/Register.php

Quote
// If you're an admin, you're special ;).
if (!$user_info['is_admin'])
{

if (!isset($_POST['options']['text_first_name']) || $_POST['options']['text_first_name'] == '')
fatal_error('Please enter your name to register.', false);

if (!isset($_POST['options']['text_last_name']) || $_POST['options']['text_last_name'] == '')
fatal_error('Please enter your lastname to register.', false);

Quote

You have to use it there, too.  See the 'options' there?  And the default_options above that?  Pick one... but they both have to be the same.

-[Unknown]

Aravot

Thanks [Unknown],

What's the difference bettween 'default_options' vs 'options'.

[Unknown]

The first is for all themes, the second for just the current.  There is no difference during registration.

-[Unknown]

Aravot

OK here is the final code, hope it's correct, I tested it works.

QuoteRegister.php

// If you're an admin, you're special ;).
if (!$user_info['is_admin'])
{

if (!isset($_POST['default_options']['text_first_name']) || $_POST['default_options']['text_first_name'] == '')
fatal_error('Please enter your name to register.', false);

if (!isset($_POST['default_options']['text_last_name']) || $_POST['default_options']['text_last_name'] == '')
fatal_error('Please enter your lastname to register.', false);


QuoteRegister.template.php

</tr><tr>
<td width="40%">
<b>First Name:</b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td>
<input type="text" name="default_options[text_first_name]" size="20" />
</td>
<tr>
</tr><tr>
<td width="40%">
<b>Last Name:</b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td>
<input type="text" name="default_options[text_last_name]" size="20" />
</td>
<tr>


QuoteProfile.template.php

</tr><tr>
<td><b>First Name: </b></td>
<td>', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '', '</td>
</tr><tr>
<td><b>Last Name: </b></td>
<td>', isset($context['member']['options']['text_last_name']) ? $context['member']['options']['text_last_name'] : '', '</td>
<tr>


QuoteProfile.template.php

echo '
</tr><tr>
<td width="40%"><b>First Name: </b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td><input type="text" name="default_options[text_first_name]" size="20" value="',isset($context['member']['options']['text_first_name'])? $context['member']['options']['text_first_name'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>Last Name: </b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td><input type="text" name="default_options[text_last_name]" size="20" value="',isset($context['member']['options']['text_last_name'])? $context['member']['options']['text_last_name'] : '', '" /></td>
<tr>

hfhs72

[unknown]

I have an additional question for you. I've followed your tutorials and the advise in the previous messages and all is working good. The data collected in the registration is outputing in the user profile just like it is supposed to.

My question:

The data that is collected in the registration can not be edited, correct? At least I can not find those fields in any of the database files. How would one go about finding and editing that data that is collected in the registration process.

For example, I have edited the register.template.php to ask for a real_name and edited the profile.templated.php file to output the data.  Everything shows up like it is supposed to. Where can I find that data that was stored?

Your help is greatly appreciated.

Don

Aravot

#11
Quote from: hfhs72 on May 08, 2005, 09:29:42 PM
My question:

The data that is collected in the registration can not be edited, correct?

Your help is greatly appreciated.

Don

If you want the data to be editable you need to add a similar code to Profile.template.php
QuoteProfile.template.php

echo '
</tr><tr>
<td width="40%"><b>First Name: </b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td><input type="text" name="default_options[text_first_name]" size="20" value="',isset($context['member']['options']['text_first_name'])? $context['member']['options']['text_first_name'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>Last Name: </b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td><input type="text" name="default_options[text_last_name]" size="20" value="',isset($context['member']['options']['text_last_name'])? $context['member']['options']['text_last_name'] : '', '" /></td>
<tr>


Try it here http://orstio.armeniancollegeofcalcutta.com I have created a custom registration it asks for user name and lastname, it displays the fields in user profile and can be changed in Forum Profile Information.

Use: test/test OR register you own it's a test site.

hfhs72

If you want the data to be editable you need to add a similar code to Profile.template.php
QuoteProfile.template.php

Thanks for the information. I've tried this out however I keep getting an error message. Where does this have to go in the profile.template.php file?


Aravot

What error message do you get? I put the code on line 100.

hfhs72

Quote from: Aravot on March 09, 2005, 11:24:02 PM
OK here is the final code, hope it's correct, I tested it works.

QuoteProfile.template.php

echo '
</tr><tr>
<td width="40%"><b>First Name: </b>
<div class="smalltext">', 'Birth name, Given name', '</div>
</td>
<td><input type="text" name="default_options[text_first_name]" size="20" value="',isset($context['member']['options']['text_first_name'])? $context['member']['options']['text_first_name'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>Last Name: </b>
<div class="smalltext">', 'Surname, Family name', '</div>
</td>
<td><input type="text" name="default_options[text_last_name]" size="20" value="',isset($context['member']['options']['text_last_name'])? $context['member']['options']['text_last_name'] : '', '" /></td>
<tr>



Can you tell me where this code goes in the Profile.template.php goes? I've got everything working except I can not get the information to show up on the Forum Profile Information page for some reason.

Thanks Aravot

Aravot

To display names in the profile you need to use the following code, the above code is for changing the names and should go after // Gender, birthdate and location around line 865, this code around line 100, hope is not confusing

QuoteProfile.template.php

</tr><tr>
<td><b>First Name: </b></td>
<td>', isset($context['member']['options']['text_first_name']) ? $context['member']['options']['text_first_name'] : '', '</td>
</tr><tr>
<td><b>Last Name: </b></td>
<td>', isset($context['member']['options']['text_last_name']) ? $context['member']['options']['text_last_name'] : '', '</td>
<tr>

hfhs72

I thought I would post all the code that I am using. All is working except for the last block of code. Whenever I put that in I get an error.

The registration is working fine. This is the code I have in the Register.php file:
if (!isset($_POST['default_options']['text_gradName']) || $_POST['default_options']['text_gradName'] == '')
fatal_error('Please enter your name to register.', false);


      if (!isset($_POST['default_options']['text_hsAttended']) || $_POST['default_options']['text_hsAttended'] == '')
fatal_error('Please enter your High School name to register.', false);

      if (!isset($_POST['default_options']['text_gradYear']) || $_POST['default_options']['text_gradYear'] == '')
fatal_error('Please enter your graduation year to register.', false);



This is the code I have in the Register.template.php file:

</tr><tr>
                       <td width="40%">
                       <b>Name at Graduation:</b>
                 <div class="smalltext">', 'First and Last name when you graduated', '</div>
                                 </td>
                           <td>
                 <input type="text" name="default_options[text_gradName]" size="30" />
                       </td>
                   <tr>


                            </tr><tr>
                       <td width="40%">
                       <b>High School Attended:</b>
                 <div class="smalltext">', '', '</div>
                                 </td>
                           <td>
                 <input type="text" name="default_options[text_hsAttended]" size="30" />
                       </td>
                   <tr>


                             </tr><tr>
                       <td width="40%">
                       <b>Graduation Year:</b>
                 <div class="smalltext">', 'If fauculty, year you left', '</div>
                                 </td>
                           <td>
                 <input type="text" name="default_options[text_gradYear]" size="10" />
                       </td>
                   <tr>
                         </td>



This is the code I have in the Profile.template.php file: (at about line 100)

</tr><tr>
                              <td><b>Name at Graduation: </b></td>
                              <td>', isset($context['member']['options']['text_gradName']) ? $context['member']['options']['text_gradName'] : '', '</td>

                   
                        </tr><tr>
                              <td><b>High School Attended: </b></td>
                              <td>', isset($context['member']['options']['text_hsAttended']) ? $context['member']['options']['text_hsAttended'] : '', '</td>                             

                        </tr><tr>
                              <td><b>Grad Year: </b></td>
                              <td>', isset($context['member']['options']['text_gradYear']) ? $context['member']['options']['text_gradYear'] : '', '</td>
                              <tr>



This code is in the Profile.template.php file under // Gender, Birthdate and Location. When ever I put this code in I get an error message that reads:

Template Parse Error!
There was a problem loading the /Themes/default/Profile.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

echo '
</tr><tr>
<td width="40%"><b>Grad Name: </b>
<div class="smalltext">', 'Name at Graduation', '</div>
</td>
<td><input type="text" name="default_options[text_gradName]" size="30" value="',isset($context['member']['options']['text_gradName'])? $context['member']['options']['text_gradName'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>High School Attended: </b>
<div class="smalltext">', 'Name of your High School', '</div>
</td>
<td><input type="text" name="default_options[text_hsAttended]" size="30" value="',isset($context['member']['options']['text_hsAttended'])? $context['member']['options']['text_hsAttended'] : '', '" /></td>
</tr><tr>
<td width="40%"><b>Graduation Year: </b>
<div class="smalltext">', 'Year you graduated high schooll', '</div>
</td>
<td><input type="text" name="default_options[text_gradYear]" size="30" value="',isset($context['member']['options']['text_gradYear'])? $context['member']['options']['text_gradYear'] : '', '" /></td>
<tr>


Please take a look at this and see if you can find what I am doing wrong.

Aravot


Aravot

#18
Updated to SMF 1.1 beta 4, I can't find the following code hence I don't know where to add my custom fields.

$sourcedir/Register.php can't find this code


// If you're an admin, you're special ;).
if (!$user_info['is_admin'])
{


Since I can't find the above code I don't know where to add the following code, any help hint is appreciated.

if (!isset($_POST['default_options']['text_first_name']) || $_POST['default_options']['text_first_name'] == '')
fatal_error('Please enter your Name to register.', false);

if (!isset($_POST['default_options']['text_last_name']) || $_POST['default_options']['text_last_name'] == '')
fatal_error('Please enter your Last Name to register.', false);

[Unknown]

#19
Put it before this:

// Set the options needed for registration.
$regOptions = array(


-[Unknown]

Advertisement: