I've got a custom profile plugin I've started developing. All is working fine for capturing and editing the profile fields for the users and administrators, but with one flaw. When the user goes to the "edit profile" screen, the fields show up but are not required. I checked and the administration interface is storing and retrieving the required settings, but they are not changing the user's edit profile screen. Code below including the edit profile page HTML.
From kamalieve.php
:
function onContentPrepareForm($form, $data)
{
// Load user_profile plugin language
$lang = JFactory::getLanguage();
$lang->load('plg_user_kamalieve', JPATH_ADMINISTRATOR);
if (!($form instanceof JForm)) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_users.profile', 'com_users.registration','com_users.user','com_admin.profile'))) {
return true;
}
if ($form->getName()=='com_users.profile')
{
// Add the profile fields to the form.
JForm::addFormPath(dirname(__FILE__).'/profiles');
$form->loadFile('profile', false);
// Toggle whether the API Key ID field is required.
if ($this->params->get('profile-require_apikeyid', 1) > 0) {
$form->setFieldAttribute('apikeyid', 'required', $this->params->get('profile-require_apikeyid') == 2, 'kamalieve');
} else {
//$form->removeField('apikeyid', 'kamalieve');
$form->setFieldAttribute('apikeyid', 'requiredFound', $this->params->get('profile-require_apikeyid'), 'kamalieve');
}
// Toggle whether the API Key Verification field is required.
if ($this->params->get('profile-require_apikeyverification', 1) > 0) {
$form->setFieldAttribute('apikeyverification', 'required', $this->params->get('profile-require_apikeyverification') == 2, 'kamalieve');
} else {
$form->removeField('apikeyverification', 'kamalieve');
}
}
Resulting HTML fieldset from the user's "edit profile" page:
<legend>Eve Online</legend>
<div class="control-group">
<div class="control-label">
<label data-original-title="<strong>API Key ID</strong><br />Enter your main character API Key ID" id="jform_kamalieve_apikeyid-lbl" for="jform_kamalieve_apikeyid" class="hasTooltip" title="">API Key ID</label>
<span class="optional">(optional)</span>
</div>
<div class="controls">
<input name="jform[kamalieve][API Key ID]" id="jform_kamalieve_apikeyid" value="12345678" size="8" type="text">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label aria-invalid="false" data-original-title="<strong>API Verification Code</strong><br />Enter your main character API Verification Code" id="jform_kamalieve_apikeyverification-lbl" for="jform_kamalieve_apikeyverification" class="hasTooltip" title="">API Verification Code</label>
<span class="optional">(optional)</span>
</div>
<div class="controls">
<input aria-invalid="false" name="jform[kamalieve][API Key Verification]" id="jform_kamalieve_apikeyverification" value="thisisatest" size="8" type="text">
</div>
</div>
Plugin's kamalieve.xml
:
<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: -->
<extension version="3.1" type="plugin" group="user">
<name>plg_user_kamalieve</name>
<author>Jamail Kamali</author>
<creationDate>November 2014</creationDate>
<copyright>(C) 2014 - 2014 Jamail Kamali. All rights reserved.</copyright>
<license>1 billion ISK to Jamail Kamali in game and do what you want.</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.yumping-amok.com</authorUrl>
<version>0.0.1</version>
<description>PLG_USER_KAMALIEVE_XML_DESCRIPTION</description>
<files>
<filename plugin="kamalieve">kamalieve.php</filename>
<filename>index.html</filename>
<folder>profiles</folder>
</files>
<languages>
<language tag="en-GB">en-GB.plg_user_kamalieve.ini</language>
<language tag="en-GB">en-GB.plg_user_kamalieve.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field name="register-require-user" type="spacer"
label="PLG_USER_KAMALIEVE_FIELD_NAME_REGISTER_REQUIRE_USER"
/>
<field name="register-require_apikeyid" type="list"
description="PLG_USER_KAMALIEVE_FIELD_APIKEYID_DESC"
label="PLG_USER_KAMALIEVE_FIELD_APIKEYID_LABEL"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
<option value="0">JDISABLED</option>
</field>
<field name="register-require_apikeyverification" type="list"
description="PLG_USER_KAMALIEVE_FIELD_APIKEYVERIFICATION_DESC"
label="PLG_USER_KAMALIEVE_FIELD_APIKEYVERIFICATION_LABEL"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
<option value="0">JDISABLED</option>
</field>
<field name="profile-require-user" type="spacer"
label="PLG_USER_KAMALIEVE_FIELD_NAME_PROFILE_REQUIRE_USER"
/>
<field name="profile-require_apikeyid" type="list"
description="PLG_USER_KAMAILIEVE_FIELD_APIKEYID_DESC"
label="PLG_USER_KAMALIEVE_FIELD_APIKEYID_LABEL"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
<option value="0">JDISABLED</option>
</field>
<field name="profile-require_apikeyverification" type="list"
description="PLG_USER_KAMAILIEVE_FIELD_APIKEYVERIFICATION_DESC"
label="PLG_USER_KAMALIEVE_FIELD_APIKEYVERIFICATION_LABEL"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
<option value="0">JDISABLED</option>
</field>
</fieldset>
</fields>
</config>
</extension>
Capture of the extension information from MySQL:
# extension_id, name, type, element, folder, client_id, enabled, access, protected, manifest_cache, params, custom_data, system_data, checked_out, checked_out_time, ordering, state
'710', 'plg_user_kamalieve', 'plugin', 'kamalieve', 'user', '0', '1', '1', '0', '{\"name\":\"plg_user_kamalieve\",\"type\":\"plugin\",\"creationDate\":\"November 2014\",\"author\":\"Jamail Kamali\",\"copyright\":\"(C) 2014 - 2014 Jamail Kamali. All rights reserved.\",\"authorEmail\":\"[email protected]\",\"authorUrl\":\"www.xxxxxxxxxx.com\",\"version\":\"0.0.1\",\"description\":\"PLG_USER_KAMALIEVE_XML_DESCRIPTION\",\"group\":\"\"}', '[]', '', '', '0', '0000-00-00 00:00:00', '0', '0'
I got the same issue and after searching on Google, came across here! The solution is that you need to go Plugin manager -> Your plugin, and then save the form once. For some reason it is not in effect by default.