downliner wrote:Thanks for the replies Ian and seva I will take a look at the link and see how it works out.
If you do find any more information Ian I would appreciate you posting your findings Thanks!
Will
Will,
I have had a hack at the register.php and profile.php to add a new section with a new field and add this as a mandatory field to the registration process. This is far from complete, but may be a start. This was completed on punbb 1.28, so line numbers may change with other versions. I have tried to keep the field names pretty generic, but obviously you will want to change them,
1) Add the new field to the database.
Add and extension column to the user table. For this example, we will add the following info:
x_extension VARCHAR(45)
2) Update the registration form
At around line 372, we need to add a new section to reflect the new field. Note that this will be added to the registration page, but you may just want to only add it to the users profile. However, this may be a good way to ensure the usually actually fills it in !
<div class="inform">
<fieldset>
<legend><?php echo $lang_prof_reg['New Section legend'] ?></legend>
<div class="infldset">
<label><?php echo $lang_prof_reg['Field Name'] ?>: <?php echo $lang_prof_reg['Field info'] ?>
<br /><select id="x_extension" name="x_extension">
<option value="choose" selected="selected">Please choose</option>
<option value="1">1</option>
<option value="2">3</option>
</select>
<br /></label>
</div>
</fieldset>
</div>
This example uses a simple pick list with a couple of values; however, can be easily changed to relfect different fields and input methods.
At around line 170, the following definition is required:
$x_extension = trim($_POST['x_extension']);
if ($x_extension == 'choose')
message($lang_prof_reg['Field mandatory']);
This code will declare the new variable and also check to make sure the user has selcted a value.
Now on about line 183, the SQL will need to be updated to add the new column.
I added x_extension as follows:
$db->query ... users( ..., x_extension) VALUES ( ... \''.$x_extension.'\') ...
Updates will also be required to the /lang/English/prof_reg.php file to include the new fields.
'Section legend' => 'The name of the new section',
'Field Name' => 'The name of the new field',
'Field info' => 'The sentance that is displayed next to the field name on the form.',
'Field mandatory' => 'Please choose a photographic brand. This field is mandatory.'
It is worth testing the registration process to ensure that the correct data is written to the database.
3) Now for the profile updates, which I have to say are even more of a hack
Open up profile.php, and on line 1473, add the following. This addes a new section and also uses the same code as register.php to display the pick list of options to the user.
else if ($section == 'newsection')
{
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
require PUN_ROOT.'header.php';
generate_profile_menu('newsection');
?>
<div class="blockform">
<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['Section New Section'] ?></span></h2>
<div class="box">
<form id="profile7" method="post" action="profile.php?section=newsection&id=<?php echo $id ?>">
<div class="inform">
<fieldset>
<legend><?php echo $lang_prof_reg['Section legend'] ?></legend>
<div class="infldset">
<input type="hidden" name="form_sent" value="1" />
<label><?php echo $lang_prof_reg['Field Name'] ?>: <?php echo $lang_prof_reg['Field info'] ?>
<br /><select name="form[x_extension]">
<option value="1"<?php if ($user['x_extension'] == '1') echo ' selected="selected"' ?>>1</option>
<option value="2"<?php if ($user['x_extension'] == '2') echo ' selected="selected"' ?>>2</option>
</select>
<br /></label>
</div>
</fieldset>
</div>
<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><?php echo $lang_profile['Instructions'] ?></p>
</form>
</div>
</div>
<?php
}
Around line 827, we need to add a new handler for the profile section.
case 'newsection':
{
$form = extract_elements(array('x_extension'));
break;
}
This extracts the posted value for update in the database. The update is via a nice piece coding, so we do not have to hard code anything here.
Now, around 885 we need to update the sql that selects the user details to populate the profile when it is first displayed. I have added the new column to the end of the user declarations.
$result = $db->query( ... u.x_extension, g.g_id, ...
Add the following to lang/profile.php to add the additional field.
'Section New Section' => 'Section Name',
This adds a new section to the profile page ... but its not finished yet ...
Open up include/functions.php and on line 310 add the following:
<li<?php if ($page == 'newsection') echo ' class="isactive"'; ?>><a href="profile.php?section=newsection&id=<?php echo $id ?>"><?php echo $lang_profile['Section New Section'] ?></a></li>
This will add the necessary menu item.
Now, all being well, this should work. Note that it is a pretty messy solution, and it really is my first attempt at giving it a go, so it may be possible to improve it a bit.
Best of luck, and let us know how you go,
Cheers, Ian