Register Extension for VldPersonals
ext.register.tpl is customized, the form's action is the register page, so error messages will go there
Howto call the Extension:
use the {register:} tag in .tpl file
ex.
<!-- INCLUDE message.tpl -->
<legend>{lang:"register","frm_register"}</legend>
<form name="register" method="post" action="{virtual_path}{ifelse:settings.fancy_urls,"1","account/register/","index.php?m=account_register"}
" enctype="multipart/form-data">
<div class="control-group" id="control-username">
<label class="control-label" for="field_username">{lang:"register","username"}</label>
<input type="text" id="field_username" onblur="checkusername(this.value)" name="username" value="{registration_username}" maxlength="32" size="32" />
<span id="field_username_status" class="help-inline" style="display:none"></span>
</div>
<label for="field_password">{lang:"register","password"}</label>
<input type="password" class="text" id="field_password" name="password" value="{registration_password}" size="20" maxlength="32" />
<label for="field_email">{lang:"register","email"}</label>
<input type="text" class="text" id="field_email" name="email" value="{registration_email}" size="32" maxlength="64" />
<label <!-- IF count.profiletypes == "1" -->style="display:none"<!-- ENDIF --> for="field_type_id">{lang:"register","user_type"}</label>
<select <!-- IF count.profiletypes == "1" -->style="display:none"<!-- ENDIF --> name="type_id" class="select" id="field_type_id" onchange="toggleProfileFields(this.value);return false;" >
{dropdownlist:profiletypes,registration_type_id}
</select>
<!-- BEGIN profile_types -->
<div id="profile_type_{type_id}" class="profile_type">
<!-- BEGIN profile_groups -->
<!-- BEGIN profile_fields -->
<label for="field_{field_label}">{field_name} {ifelse:field_required,"1","<i>*</i>",""}</label>
<!-- IF field_type = "text" -->
<!-- IF field_label = "city" -->
<input type="text" id="field_{field_label}" name="{field_label}" style="width: {field_width}" value="{top.city}" maxlength="{field_maxlength}" />
<!-- ELSE -->
<input type="text" id="field_{field_label}" name="{field_label}" style="width: {field_width}" value="{htmlentities:field_value}" maxlength="{field_maxlength}" />
<!-- ENDIF -->
<!-- ELSEIF field_type = "image" -->
<input type="file" id="field_{field_label}" name="{field_label}" />
<!-- IF field_value != "" -->
<a target="_blank" href="{top.virtual_pic_path}{field_value}">View file</a>
<label class="checkbox">
<input class="checkbox" id="{field_label}_remove" name="{field_label}_remove" type="checkbox" value="1"> {lang:"profile","remove"}
</label>
<!-- ENDIF -->
<!-- ELSEIF field_type = "textarea" -->
<textarea class="textarea" id="field_{field_label}" name="{field_label}" style="width: {field_width}; height: {field_height}">{htmlentities:field_value}</textarea>
<!-- ELSEIF field_type = "checkbox" -->
<!-- INBEGIN field_items -->
<label class="checkbox">
{checkboxes:parent.field_label,rowcnt,parent.field_value,inner_key} {inner_value}
</label>
<!-- END field_items -->
<!-- ELSEIF field_type = "radio" -->
<!-- INBEGIN field_items -->
<label class="radio">
{radiobuttons:parent.field_label,rowcnt,parent.field_value,inner_key} {inner_value}
</label>
<!-- END field_items -->
<!-- ELSEIF field_type = "combo" -->
<!-- IF field_label = "country" AND top.country_id -->
<select class="chzn-select" id="field_{field_label}" name="{field_label}">{dropdownlist:field_items,top.country_id}</select>
<!-- ELSE -->
<select class="chzn-select<!-- IF field_label = "gender1" OR field_label = "gender2" -->-nosearch<!-- ENDIF -->" id="field_{field_label}" name="{field_label}">{dropdownlist:field_items,field_value}</select>
<!-- ENDIF -->
<!-- ELSEIF field_type = "birthday" -->
<!-- IF session.timeformat -->
<select class="chzn-select input-small" style="width:100px;" name="{field_label}_month">{dropdownlist:top.months,field_value_month}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_day">{dropdownlist:top.days,field_value_day}</select>
<!-- ELSE -->
<select class="chzn-select input-small" style="width:100px;" name="{field_label}_month">{dropdownlist:top.months,field_value_day}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_day">{dropdownlist:top.days,field_value_month}</select>
<!-- ENDIF -->
<select class="chzn-select input-small" style="width:70px;" name="{field_label}_year">{dropdownlist:top.birthday_years,field_value_year}</select>
<!-- ELSEIF field_type = "date" -->
<select class="chzn-select input-small" style="width:100px;" name="{field_label}_month">{dropdownlist:top.months,field_value_month}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_day">{dropdownlist:top.days,field_value_day}</select>
<select class="chzn-select input-small" style="width:70px;" name="{field_label}_year">{dropdownlist:years,field_value_year}</select>
<!-- ELSEIF field_type = "time" -->
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_hour">{dropdownlist:top.hours,field_value_hour}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_minute">{dropdownlist:top.minutes,field_value_minute}</select>
<!-- ELSEIF field_type = "datetime" -->
<select class="chzn-select input-small" style="width:100px;" name="{field_label}_month">{dropdownlist:top.months,field_value_month}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_day">{dropdownlist:top.days,field_value_day}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_year">{dropdownlist:years,field_value_year}</select> @
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_hour">{dropdownlist:top.hours,field_value_hour}</select>
<select class="chzn-select input-small" style="width:50px;" name="{field_label}_minute">{dropdownlist:top.minutes,field_value_minute}</select>
<!-- ENDIF -->
<!-- END profile_fields -->
<!-- END profile_groups -->
<!-- END ext_register_profile_types -->
<!-- IF settings.enable_registration_photo -->
<label for="field_photo">{lang:"register","select_picture"} <!-- IF settings.require_registration_photo --><i>*</i><!-- ENDIF --></label>
<input id="field_photo" type="file" name="photo" value="" class="text" />
<!-- ENDIF -->
<!-- IF is_captcha -->
<label for="field_verification">{lang:"register","verify_number"}</label>
<input type="text" id="field_verification" class="text captcha" name="captcha" maxlength="5" /> <img src="{virtual_path}includes/fns/fns.captcha.php" alt="" border="0" class="captcha" /><div class="clear"></div>
<!-- ENDIF -->
<!-- IF is_tos -->
<label for="field_tos">{lang:"register","accept_tos"} <a target="_blank" href="{virtual_path}{ifelse:settings.fancy_urls,"1","page/tos/","index.php?m=pages&p=tos"}">{lang:"register","tos"}</a></label>
<select id="field_tos" class="chzn-select-nosearch" name="tos">{dropdownlist:top.yesnobox,1}</select>
<!-- ENDIF -->
<input type="hidden" name="isregister" value="1" />
<div class="form-actions">
<input class="btn btn-success btn-block" name="submit" type="submit" value="{lang:"register","submit"}" /> </div>
</div>
</form>
<?php
/*
=====================================================
vldPersonals - by VLD Interactive
----------------------------------------------------
http://www.vldpersonals.com/
http://www.vldinteractive.com/
-----------------------------------------------------
Copyright (c) 2005-2011 VLD Interactive
=====================================================
THIS IS COPYRIGHTED SOFTWARE
PLEASE READ THE LICENSE AGREEMENT
http://www.vldpersonals.com/agreement/
=====================================================
*/
$data = array(
'name' => 'Registration Form',
'about' => 'Display Registration form.',
'author' => 'Andrea Valla',
'email' => 'valla.andrea@gmail.com',
'help' => '',
'website' => '',
);
function vldext_register ()
{
global $DB, $LANG, $TEMPLATE, $SESSION, $PREFS;
include SYS_PATH . 'includes/languages/' . SYS_LANG . '/lang.lib.account_register.php';
include SYS_PATH . 'includes/fns/fns.validate.php';
include SYS_PATH . 'includes/core/core.image.php';
$template="ext.register.tpl";
//------------------------------------------------
// GeoIp recognize country and city
//------------------------------------------------
$country_name = getenv('GEOIP_COUNTRY_NAME');
$country_code = getenv('GEOIP_COUNTRY_CODE');
$city = getenv('GEOIP_CITY');
//------------------------------------------------
// Check if registration is allowed
//------------------------------------------------
if ($PREFS->conf['allow_registration'] != 1)
{
$TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1);
return 0;
}
//------------------------------------------------
// Set default values
//------------------------------------------------
$username = isset($_POST['username']) && $_POST['username'] ? $DB->strip_slashes(trim($_POST['username'])) : "";
$password = isset($_POST['password']) && $_POST['password'] ? $DB->strip_slashes(trim($_POST['password'])) : "";
$password_confirm = isset($_POST['password_confirm']) && $_POST['password_confirm'] ? $DB->strip_slashes(trim($_POST['password_confirm'])) : "";
$email = isset($_POST['email']) && $_POST['email'] ? $DB->strip_slashes(trim($_POST['email'])) : "";
$email_confirm = isset($_POST['email_confirm']) && $_POST['email_confirm'] ? $DB->strip_slashes(trim($_POST['email_confirm'])) : "";
$type_id = isset($_POST['type_id']) && is_numeric($_POST['type_id']) ? (isset($PREFS->conf['profile_types'][$_POST['type_id']]) ? intval($_POST['type_id']) : 0) : $PREFS->conf['default_profile_type'];
$captcha = isset($_POST['captcha']) && $_POST['captcha'] ? $DB->strip_slashes(trim($_POST['captcha'])) : "";
$tos = isset($_POST['tos']) && $_POST['tos'] ? 1 : 0;
$photo = isset($_FILES['photo']) ? $_FILES['photo'] : "";
$t = $index_type_id = 0;
$fields = $default_fields = array();
//------------------------------------------------
// Parse profile groups and fields
//------------------------------------------------
foreach ($PREFS->conf['profile_types'] as $profile_type)
{
$i = 0;
$fields[$t]['type_id'] = $profile_type['type_id'];
$fields[$t]['type_label'] = $profile_type['type_label'];
$fields[$t]['type_name'] = $profile_type['type_name'];
foreach ($profile_type['profile_groups'] as $profile_group)
{
$j = 0;
//------------------------------------------------
// Assign dynamic group
//------------------------------------------------
if ($profile_group['group_in_registration'])
{
$fields[$t]['profile_groups'][$i] = $profile_group;
$fields[$t]['profile_groups'][$i]['profile_fields'] = array();
//------------------------------------------------
// Assign static group
//------------------------------------------------
$TEMPLATE->assign('profile_group_' . $profile_group['group_label'], $profile_group['group_name']);
}
foreach ($profile_group['profile_fields'] as $profile_field)
{
if ($profile_field['field_in_registration'] && $profile_group['group_in_registration'])
{
//------------------------------------------------
// Assign dynamic field
//------------------------------------------------
$fields[$t]['profile_groups'][$i]['profile_fields'][$j] = $profile_field;
//------------------------------------------------
// Create years
//------------------------------------------------
if ($profile_field['field_type'] == "date" || $profile_field['field_type'] == "time" || $profile_field['field_type'] == "datetime")
{
$default_years = explode("\n", $profile_field['field_default'], 2);
if ( count($default_years) == 2 ) {
$startyear = date("Y") + $default_years[0];
$endyear = date("Y") + $default_years[1];
}
else {
$startyear = $endyear = date("Y");
}
$years = array();
for ($y = $startyear; $y <= $endyear; $y++) {
$years[$y] = $y;
}
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['years'] = $years;
}
//------------------------------------------------
// Set value
//------------------------------------------------
$value = $profile_field['field_type'] != "checkbox" ? '' : array();
if (isset($_POST['isregister']) && $_POST['isregister'] && $profile_type['type_id'] == $type_id)
{
$index_type_id = $t;
//------------------------------------------------
// Set custom
//------------------------------------------------
if ($profile_field['field_type'] == "birthday")
{
$date_day = isset($_POST[$profile_field['field_label'].'_day']) && $_POST[$profile_field['field_label'].'_day'] ? intval($_POST[$profile_field['field_label'].'_day']) : 0;
$date_month = isset($_POST[$profile_field['field_label'].'_month']) && $_POST[$profile_field['field_label'].'_month'] ? intval($_POST[$profile_field['field_label'].'_month']) : 0;
$date_year = isset($_POST[$profile_field['field_label'].'_year']) && $_POST[$profile_field['field_label'].'_year'] ? intval($_POST[$profile_field['field_label'].'_year']) : 0;
$value = ( $date_day && $date_month && $date_year ) ? str_pad($date_year, 4, "0", STR_PAD_LEFT) . str_pad($date_month, 2, "0", STR_PAD_LEFT) . str_pad($date_day, 2, "0", STR_PAD_LEFT) : '';
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = $date_day;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = $date_month;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = $date_year;
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_day', $date_day);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_month', $date_month);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_year', $date_year);
}
elseif ($profile_field['field_type'] == "date" || $profile_field['field_type'] == "time" || $profile_field['field_type'] == "datetime")
{
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute']= isset($_POST[$profile_field['field_label'].'_minute']) && $_POST[$profile_field['field_label'].'_minute'] ? intval($_POST[$profile_field['field_label'].'_minute']) : 0;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour'] = isset($_POST[$profile_field['field_label'].'_hour']) && $_POST[$profile_field['field_label'].'_hour'] ? intval($_POST[$profile_field['field_label'].'_hour']) : 0;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = isset($_POST[$profile_field['field_label'].'_day']) && $_POST[$profile_field['field_label'].'_day'] ? intval($_POST[$profile_field['field_label'].'_day']) : 0;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = isset($_POST[$profile_field['field_label'].'_month']) && $_POST[$profile_field['field_label'].'_month'] ? intval($_POST[$profile_field['field_label'].'_month']) : 0;
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = isset($_POST[$profile_field['field_label'].'_year']) && $_POST[$profile_field['field_label'].'_year'] ? intval($_POST[$profile_field['field_label'].'_year']) : 0;
$value = mktime($fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute'], 0, $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'], $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year']);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_minute', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_minute']);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_hour', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_hour']);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_day', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day']);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_month', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month']);
$TEMPLATE->assign('profile_field_' . $profile_field['field_label'] . '_value_year', $fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year']);
}
elseif ($profile_field['field_type'] == "checkbox")
{
$value = ( isset($_POST[$profile_field['field_label']]) ) ? $_POST[$profile_field['field_label']] : array();
}
elseif ($profile_field['field_type'] == "textarea")
{
$value = isset($_POST[$profile_field['field_label']]) ? $DB->strip_slashes(trim($_POST[$profile_field['field_label']])) : "";
$value = str_replace("\r", '', $value);
$value = preg_replace('/[ ]+/', ' ', $value);
$value = preg_replace('/\n{3,}/', "\n\n", $value);
$value = filter_wordwrap($value);
}
else
{
$value = isset($_POST[$profile_field['field_label']]) ? $DB->strip_slashes(trim($_POST[$profile_field['field_label']])) : "";
}
//------------------------------------------------
// Apply filter if necessary
//------------------------------------------------
if ($SESSION->conf['apply_word_filter'] && ($profile_field['field_type'] == "textarea" || $profile_field['field_type'] == "text")) {
$value = filter_words($value);
}
//------------------------------------------------
// Assign dynamic field
//------------------------------------------------
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value'] = $value;
}
else
{
if ( in_array($profile_field['field_type'], array("radio", "combo")) )
{
if ($profile_field["field_label"] == "country") {
foreach ($profile_field["field_items"] as $key => $value) {
if (strtoupper($value) == strtoupper($country_name))
{
$country_id = $key;
}
}
}
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value'] = $profile_field['field_default'];
}
elseif ( in_array($profile_field['field_type'], array("date", "datetime", "time", "birthday")) )
{
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_day'] = '';
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_month'] = '';
$fields[$t]['profile_groups'][$i]['profile_fields'][$j]['field_value_year'] = '';
}
}
//------------------------------------------------
// Assign static field
//------------------------------------------------
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_name', $profile_field['field_name']);
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_type', $profile_field['field_type']);
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_maxlength', $profile_field['field_maxlength']);
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_default', $profile_field['field_default']);
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_items', $profile_field['field_items']);
$TEMPLATE->assign('profile_field_' . $profile_type['type_label'] . '_' . $profile_field['field_label'] . '_value', $value);
$j++;
}
elseif ( $profile_type['type_id'] == $type_id )
{
$default_fields[] = $profile_field;
}
}
if ($profile_group['group_in_registration'])
{
$i++;
}
}
$t++;
}
//------------------------------------------------
// Set default birthday
//------------------------------------------------
$birthday_day = 1;
$birthday_month = 1;
$birthday_year = date("Y") - $PREFS->conf['min_age'];
$_SESSION['captcha'] = random_string(5);
//------------------------------------------------
// Create minutes array
//------------------------------------------------
for ($i = 0; $i <= 59; $i++)
$minutes[str_pad($i, 2, '0', STR_PAD_LEFT)] = str_pad($i, 2, '0', STR_PAD_LEFT);
//------------------------------------------------
// Create hours array
//------------------------------------------------
for ($i = 0; $i <= 23; $i++)
$hours[str_pad($i, 2, '0', STR_PAD_LEFT)] = str_pad($i, 2, '0', STR_PAD_LEFT);
//------------------------------------------------
// Create days array
//------------------------------------------------
for ($i = 1; $i <= 31; $i++)
$days[$i] = $i;
//------------------------------------------------
// Create years array
//------------------------------------------------
$startyear = date("Y") - $PREFS->conf['min_age'];
$endyear = date("Y") - 90;
$birthdayyears = array();
for ($i = $startyear; $i >= $endyear; $i--)
$birthdayyears[$i] = $i;
//------------------------------------------------
// Create months array
//------------------------------------------------
$months[1] = ($LANG['core']['bday_january']);
$months[2] = ($LANG['core']['bday_february']);
$months[3] = ($LANG['core']['bday_march']);
$months[4] = ($LANG['core']['bday_april']);
$months[5] = ($LANG['core']['bday_may']);
$months[6] = ($LANG['core']['bday_june']);
$months[7] = ($LANG['core']['bday_july']);
$months[8] = ($LANG['core']['bday_august']);
$months[9] = ($LANG['core']['bday_september']);
$months[10] = ($LANG['core']['bday_october']);
$months[11] = ($LANG['core']['bday_november']);
$months[12] = ($LANG['core']['bday_december']);
//------------------------------------------------
// Create yes/no array
//------------------------------------------------
$yesnobox[1] = ($LANG['core']['yes']);
$yesnobox[0] = ($LANG['core']['no']);
//------------------------------------------------
// Get profile types
//------------------------------------------------
$profiletypes = get_profile_types(1);
//------------------------------------------------
// Assign template vars
//------------------------------------------------
$TEMPLATE->assign("registration_username", htmlentities2utf8($username));
$TEMPLATE->assign("registration_password", htmlentities2utf8($password));
$TEMPLATE->assign("registration_password_confirm", htmlentities2utf8($password_confirm));
$TEMPLATE->assign("registration_email", htmlentities2utf8($email));
$TEMPLATE->assign("registration_email_confirm", htmlentities2utf8($email_confirm));
$TEMPLATE->assign("registration_type_id", $type_id);
$TEMPLATE->assign("is_tos", $PREFS->conf['registration_tos']);
$TEMPLATE->assign("is_captcha", $PREFS->conf['registration_captcha'] && extension_loaded('gd'));
$TEMPLATE->assign("registration_tos", $tos);
$TEMPLATE->assign("days", $days);
$TEMPLATE->assign("months", $months);
$TEMPLATE->assign("birthday_years", $birthdayyears);
$TEMPLATE->assign("minutes", $minutes);
$TEMPLATE->assign("hours", $hours);
$TEMPLATE->assign("profile_types", $fields);
$TEMPLATE->assign("yesnobox", $yesnobox);
$TEMPLATE->assign("profiletypes", $profiletypes);
if (!is_null($country_name)) {
$TEMPLATE->assign("country_name", $country_name);
}
if (!is_null($country_code)) {
$TEMPLATE->assign("country_code", $country_code);
}
if (!is_null($country_id)) {
$TEMPLATE->assign("country_id", $country_id);
}
if (!is_null($city)) {
$TEMPLATE->assign("city", $city);
}
$TEMPLATE->output($template);
}
?>