【问题标题】:Joomla 3.x - How to add & access data attribute in jFormJoomla 3.x - 如何在 jForm 中添加和访问数据属性
【发布时间】:2017-10-11 23:49:53
【问题描述】:

例如,

<field name="name" type="text" required="ture" data-attribute-type="Guest" data-attribute-subtype="Guest1"/>

这里我添加了 data-attribute-type="Guest"data-attribute-subtype="Guest1" 这些属性并为其赋值。现在我想在渲染 jForm 时访问这些属性/值

<input type="text" name="jform[name]" id="jform_name" required="required" data-attribute-type="Guest" data-attribute-subtype="Guest1" >

【问题讨论】:

标签: joomla3.2


【解决方案1】:

您需要通过elements 数组访问自定义属性,如下所示:

表单字段(我认为你不想使用data 属性):

<field name="myfieldname" type="myfieldname" required="true" access-type="Guest" access-subtype="Guest1"/>

然后你需要定义一个自定义字段并发挥你的作用(可能在renderrenderField

class JFormFieldMyFieldName extends JFormField
{
    public function renderField($options = array())
    {
        $access_type = $this->element['access_type']);
        $access_subtype = $this->element['access_subtype']);

        // do whatever
    }
}

这一切都未经测试,但希望能让你朝着正确的方向前进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2018-10-28
    • 2017-12-23
    • 2015-10-29
    • 1970-01-01
    相关资源
    最近更新 更多