简体   繁体   English

如何在joomla中创建注册表单中的选择框

[英]how to create select box in registration form in joomla

how to create select box in registration form in joomla. 如何在joomla中创建注册表单中的选择框。

I have try to add birthyear in my registration form using dynamic. 我尝试使用动态在我的注册表单中添加birthyear。

option value from 1950 to current year.how to add the year using loops or dynamic code. 1950年到当前年份的选项值。使用循环或动态代码添加年份。

Here is my code. 这是我的代码。

<field name="joinyear" type="list"
        description="COM_USERS_REGISTER_JOINYEAR_LABEL"
        filter="string"
        label="COM_USERS_REGISTER_JOINYEAR_DESC"
        message="COM_USERS_REGISTER_JOINYEAR_DESC"
        required="true">
    <option value="2013">2013</option>
    <option value="2012">2012</option>
    <option value="2011">2011</option>
    .
    .
    .
    .
    .
    <option value="1950">1950</option>
</field>

Actually I'd recommend you to create your own list type: create a directory /models/fields/year.php which will extend JFormFieldList class defined in /libraries/joomla/form/fields/list.php 实际上我建议你创建自己的列表类型:创建一个目录/models/fields/year.php,它将扩展/libraries/joomla/form/fields/list.php中定义的JFormFieldList类。

And add there the following code: 并添加以下代码:

<?php
defined('JPATH_PLATFORM') or die;

JFormHelper::loadFieldClass('list');

class JFormFieldYear extends JFormFieldList
{
    protected $type = 'Year';

    protected function getOptions()
    {
        $options = array();         
        $yearNow = date('Y');

        for ($i = 1950; $i <= $yearNow; $i++)
        {
            $tmp = JHtml::_('select.option', $i, $i, 'value', 'text', false);
            $options[] = $tmp;
        }

        reset($options);

        return $options;
    }
}

And then in your xml type define type="year" instead of type="list" for a field like this: 然后在你的xml类型中为这样的字段定义type =“year”而不是type =“list”:

<field name="joinyear" type="year"
        description="COM_USERS_REGISTER_JOINYEAR_LABEL"
        filter="string"
        label="COM_USERS_REGISTER_JOINYEAR_DESC"
        message="COM_USERS_REGISTER_JOINYEAR_DESC"
        required="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM