0

joomla 2.5登録にドロップダウンを追加したいと思っています.sqlフォームフィールドタイプを使用できると思いますが、そのsqlが特定の都市(登録フォームにある)のすべての学校を返すようにしたい.だから問題は、sqlクエリがどのようになるかですパラメータを受け入れますか?

4

1 に答える 1

0

models==>fieldsに1つのフィールドタイプを作成する必要があります。

例:schools.phpとしてphpファイルを作成し、次のコードを含めます。

==> schools.php(ファイル名)

defined('JPATH_BASE') or die;

class JFormFieldSchools extends JFormField
{   
protected $type = 'Schools';

protected function getInput()
{
    // Initialize variables.
    $html = array();
    $attr = '';

    // Initialize some field attributes.
    $attr .= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
    $attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
    $attr .= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';

    // Initialize JavaScript field attributes.
    $attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';

    // Get some field values from the form.
    $contactId  = (int) $this->form->getValue('id');
    $categoryId = (int) $this->form->getValue('catid');

    // Build the query for the ordering list.
    $query = 'SELECT ordering AS value, name AS text' .
            ' FROM #__contact_details' .
            ' WHERE catid = ' . (int) $categoryId .
            ' ORDER BY ordering';

    // Create a read-only list (no name) with a hidden input to store the value.
    if ((string) $this->element['readonly'] == 'true') {
        $html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $contactId ? 0 : 1);
        $html[] = '<input type="hidden" name="'.$this->name.'" value="'.$this->value.'"/>';
    }
    // Create a regular list.
    else {
        $html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $contactId ? 0 : 1);
    }

    return implode($html);
}
}

次に、必要に応じてmysqlクエリを変更する必要があります。

デフォルトのjoomla登録ページで変更する必要がある場合は、次のパス(... / com_users / models / forms / registerration.xml)を使用してください。

  <field name="xxxxx" type="Schools"
description="COM_USERS_REGISTER_NAME_DESC"
filter="string"
label="COM_USERS_REGISTER_NAME_LABEL"
message="COM_USERS_REGISTER_NAME_MESSAGE"
required="true"
size="30" />
于 2012-08-11T10:51:57.290 に答える