Cupara
Well-known member
I'm having issues and not sure why but I'm using template modification to add the new field to the registration form.
When the form is submitted everything is added to the user table but the code isn't being passed.
Template Mod:
xfPoints_DataWriter_User:
If I fill the field via phpMySQLAdmin then approve the account it will grab the right data and alter the xfpoints_currency field. So the if condition above is working fine, just having an issue inserting the field from the form to the database.
When the form is submitted everything is added to the user table but the code isn't being passed.
Template Mod:
HTML:
<fieldset>
<dl class="ctrlUnit">
<dt><label for="ctrl_xfpoints_code">{xen:phrase xfpoints_promotion_code}:</label></dt>
<dd><input type="text" name="xfpoints_code" class="textCtrl OptOut" id="ctrl_xfpoints_code" /></dd>
</dl>
</fieldset>
xfPoints_DataWriter_User:
PHP:
<?php
class xfPoints_DataWriter_User extends XFCP_xfPoints_DataWriter_User
{
protected function _getFields()
{
$fields = parent::_getFields();
$fields['xf_user'] += array('xfpoints_code' => array('type' => self::TYPE_STRING, 'default' => '0'));
return $fields;
}
/**
* Post-save handling.
*/
protected function _postSave()
{
$options = XenForo_Application::get('options');
$visitor = XenForo_Visitor::getInstance();
$promoModel = $this->_getPromotionModel();
$promo = $promoModel->getCodeByCode($this->get('xfpoints_code'));
if ($promo['code'])
{
parent::_postSave();
$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
$addPoints = false;
if ($this->get('user_state') == 'valid')
{
if ($this->isInsert())
{
$addPoints = true;
}
else if ($this->isChanged('user_state'))
{
$previousState = $this->getExisting('user_state');
if ($previousState == 'moderated' || $previousState == 'email_confirm')
{
$addPoints = true;
}
}
}
if ($addPoints)
{
$pointsEarned = $promo['amount'];
$pointsModel->updateUserPoints($this->get('user_id'), $pointsEarned);
}
} else {
if ($options->xfpoints_currency_register > '0')
{
parent::_postSave();
$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
$addPoints = false;
if ($this->get('user_state') == 'valid')
{
if ($this->isInsert())
{
$addPoints = true;
}
else if ($this->isChanged('user_state'))
{
$previousState = $this->getExisting('user_state');
if ($previousState == 'moderated' || $previousState == 'email_confirm')
{
$addPoints = true;
}
}
}
if ($addPoints)
{
$pointsEarned = $this->getModelFromCache('xfPoints_Model_Currency')->assignUserPoints($this->get('user_id'), 'register');
$pointsModel->updateUserPoints($this->get('user_id'), $pointsEarned);
}
}
}
}
protected function _getPromotionModel()
{
return $this->getModelFromCache('xfPoints_Model_Promotion');
}
}
If I fill the field via phpMySQLAdmin then approve the account it will grab the right data and alter the xfpoints_currency field. So the if condition above is working fine, just having an issue inserting the field from the form to the database.