public function actionCustomField()
public function actionCustomFieldSave()
UPDATE xf_user_field SET display_group = 'mycustomfields' WHERE field_id IN ('custom_1', 'custom_2', 'custom_3')
public function actionCustomField(){
.................................................
.................................................
$customFields = $this->_getFieldModel()->getUserFields(
array('display_group' => 'mycustomfields'),
array('valueUserId' => $visitor['user_id'])
);
.................................................
.................................................
}
Or, is it okay if I manually change the value of display_group in the xf_user_field database table to "mycustomfields" for my intended custom fields:
And then change my function asCode:UPDATE xf_user_field SET display_group = 'mycustomfields' WHERE field_id IN ('custom_1', 'custom_2', 'custom_3')
PHP:public function actionCustomField(){ ................................................. ................................................. $customFields = $this->_getFieldModel()->getUserFields( array('display_group' => 'mycustomfields'), array('valueUserId' => $visitor['user_id']) ); ................................................. ................................................. }
Is there any implication of this manual thing other than that it is an ugly solution?
<xen:foreach loop="$userFieldsInfo" key="$fieldId" value="$fieldInfo">
{xen:helper userFieldTitle, $fieldId}:{$fieldInfo.display_group}<br>
</xen:foreach>
<?php
class AbdFahim_CustomField_Install
{
public static function install()
{
$db = XenForo_Application::get('db');
try
{
$db->query("ALTER TABLE `xf_user_field` CHANGE `display_group` `display_group` ENUM('personal','contact','preferences','mycustomfields')
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'personal';");
$db->query("UPDATE xf_user_field SET display_group = 'mycustomfields' WHERE field_id IN ('custom_1', 'custom_2',
'custom_3')");
}
catch (Zend_Db_Exception $e) {}
}
}
Hi,
I am facing slight issues with my addon. The display_group of a custom field is not showing the changed value as in database:
View attachment 155017
In Forum:
View attachment 155018
All I did was display custom field and type:
Code:<xen:foreach loop="$userFieldsInfo" key="$fieldId" value="$fieldInfo"> {xen:helper userFieldTitle, $fieldId}:{$fieldInfo.display_group}<br> </xen:foreach>
In the addon install.php file, I changed the display_group using following code
Code:<?php class AbdFahim_CustomField_Install { public static function install() { $db = XenForo_Application::get('db'); try { $db->query("ALTER TABLE `xf_user_field` CHANGE `display_group` `display_group` ENUM('personal','contact','preferences','mycustomfields') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'personal';"); $db->query("UPDATE xf_user_field SET display_group = 'mycustomfields' WHERE field_id IN ('custom_1', 'custom_2', 'custom_3')"); } catch (Zend_Db_Exception $e) {} } }
Do I need to change it anywhere else? Or clear some cache?
XenForo_Model::create('XenForo_Model_UserField')->rebuildUserFieldCache()
public function actionCustomFieldSave()
{
$this->_assertPostOnly();
if (!XenForo_Visitor::getInstance()->canEditProfile())
{
return $this->responseNoPermission();
}
$customFields = $this->_input->filterSingle('custom_fields', XenForo_Input::ARRAY_SIMPLE);
$customFieldsShown = $this->_input->filterSingle('custom_fields_shown', XenForo_Input::STRING, array('array' => true));
$writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
$writer->setExistingData(XenForo_Visitor::getUserId());
$writer->setCustomFields($customFields, $customFieldsShown);
$writer->preSave();
if ($dwErrors = $writer->getErrors())
{
return $this->responseError($dwErrors);
}
$writer->save();
$redirectParams = array();
if ($this->_noRedirect())
{
$user = $writer->getMergedData();
}
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildPublicLink('account/custom-field'),
null,
$redirectParams
);
}
Looks good to me.Thanks a lot, it worked perfectly after adding that line at the end of install.php and uninstall.php. This is now running in my live site, thanks for your awesome help.
One last thing, though I have not faced any issue so far, can you please have a glance at my save function and advise if I need to add any specific function (like rebuilding cache) for this?
Code:public function actionCustomFieldSave() { $this->_assertPostOnly(); if (!XenForo_Visitor::getInstance()->canEditProfile()) { return $this->responseNoPermission(); } $customFields = $this->_input->filterSingle('custom_fields', XenForo_Input::ARRAY_SIMPLE); $customFieldsShown = $this->_input->filterSingle('custom_fields_shown', XenForo_Input::STRING, array('array' => true)); $writer = XenForo_DataWriter::create('XenForo_DataWriter_User'); $writer->setExistingData(XenForo_Visitor::getUserId()); $writer->setCustomFields($customFields, $customFieldsShown); $writer->preSave(); if ($dwErrors = $writer->getErrors()) { return $this->responseError($dwErrors); } $writer->save(); $redirectParams = array(); if ($this->_noRedirect()) { $user = $writer->getMergedData(); } return $this->responseRedirect( XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/custom-field'), null, $redirectParams ); }
Apologies for the epic bump here, but I haven't had much luck coming up with an add on that will do this.
I'm a bit intimidated diving in to editing Xenforo's core files myself, but am willing to give it a go. However, the linked to resource for extending the class ( https://xenforo.com/community/threa...nsert-tabs-in-profile-page-using-hooks.21289/ ) seems like it's part way through a larger tutorial. Should I just start at this step, or do I need to go from the beginning?
We use essential cookies to make this site work, and optional cookies to enhance your experience.