Why is my Joomla profile plugin (3.3.6) not recognizing required fields?

I have a custom profile plugin that I started developing. Everything works fine for capturing and editing profile fields for users and admins, but with one drawback. When the user goes to the Edit Profile screen, the fields are displayed but not required. I have checked and the admin interface stores and retrieves the required settings, but they do not change the user edit profile screen. The code below includes an HTML profile edit page.

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');
                    }

            }

      

The resulting set of HTML fields on 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 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>jamail_kamali_sc@gmail.com</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>

      

Grabbing 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\":\"xxxxxxxxxx@gmail.com\",\"authorUrl\":\"www.xxxxxxxxxx.com\",\"version\":\"0.0.1\",\"description\":\"PLG_USER_KAMALIEVE_XML_DESCRIPTION\",\"group\":\"\"}', '[]', '', '', '0', '0000-00-00 00:00:00', '0', '0'

      

+3


source to share


1 answer


I have the same problem and came across after googling! The solution is that you need to go to Plugin Manager -> Plugin and then save the form once. For some reason, it doesn't work by default.



0


source







All Articles