为什么我的Joomla(3.3.6)Profile Plugin识别必填字段?

时间:2014-11-29 10:17:32

标签: php plugins joomla profile

我已经开始开发自定义配置文件插件了。所有这些都可以很好地捕获和编辑用户和管理员的配置文件字段,但有一个缺陷。当用户进入“编辑配置文件”屏幕时,字段显示但不是必需的。我检查过,管理界面正在存储和检索所需的设置,但它们没有更改用户的编辑配置文件屏幕。下面的代码包括编辑个人资料页面HTML。

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

            }

来自用户“编辑个人资料”页面的结果HTML字段集:

<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>

插件的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>

从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'

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在Google上搜索后,发现了这里!解决方案是你需要去插件管理器 - &gt;您的插件,然后保存表单一次。出于某种原因,默认情况下它不起作用。