简体   繁体   English

Joomla! 通过调用数据库填充注册表上的列表框

[英]Joomla! Populate List Box on Registration Form by calling DB

Thanks in advance for your help... 在此先感谢您的帮助...

I have modified the registration.xml file and other files as necessary to add additional forms to my registration form on mhy Joomla! 我已根据需要修改了registration.xml文件和其他文件,以将其他表单添加到Mhy Joomla的注册表单中! site. 现场。 The fields are currently all text boxes and I want to create list boxes for items like state. 该字段当前是所有文本框,我想为状态之类的项目创建列表框。 I don't want to type in the options and values, but rather pull from a table on the database. 我不想输入选项和值,而是从数据库的表中提取。

This code in my registration.xml file works: 我的registration.xml文件中的以下代码有效:

<field name="statelist2" type="list" 
default=""
label="COM_USERS_REGISTER_STATE_LABEL"
description="COM_USERS_REGISTER_STATE_DESC"
message="COM_USERS_REGISTER_STATE_MESSAGE">
<option value="CT">CT</option>
<option value="MA">MA</option>
</field>

This code in my registration.xml file does NOT work and I tried removing the call to the DB to just get the page to load with some php: 我的registration.xml文件中的此代码不起作用,我尝试删除对DB的调用以仅使页面加载一些php:

<field name="statelist" 
type="list"
default=""
label="COM_USERS_REGISTER_STATE_LABEL"
description="COM_USERS_REGISTER_STATE_DESC"
message="COM_USERS_REGISTER_STATE_MESSAGE">
<?php
$x = "CT";
$z = "NY";
echo "<option value='" . $x. "'>" . $x . "</option>"; 
echo "<option value='" . $z. "'>" . $z . "</option>"; 
?>
</field>

My question(s): 1) Where do I have to put the code (in what file) in order to either create the list box or populate it with potential values? 我的问题:1)为了创建列表框或用潜在值填充列表框,我必须在哪里放置代码(在哪个文件中)?

2) In order to take advantage of the existing Joomla! 2)为了利用现有的Joomla! framework, I see in the registration.php files some functions for loadFormData and getData - can I put code in there to populate items in the registration form after it's been rendered? 框架,我在registration.php文件中看到一些loadFormData和getData的函数-可以在渲染表单后在其中放置代码以填充注册表中的项目吗? I was thinking something like this, but not sure. 我在想这样的事情,但不确定。

<?php 
    //init Joomla Framework 
    define( '_JEXEC', 1 ); 
    define( 'DS', DIRECTORY_SEPARATOR ); 
    define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' )); 


    require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); 
    require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); 

    $mainframe = JFactory::getApplication('site'); 

    //DBQuery 
    $database =& JFactory::getDBO(); 
    $query = "SELECT * FROM #__tbl_State;"; 

$database->setQuery($query); 
    //$result = $database->query();
$items = ($items = $db->loadObjectList())?$items:array(); 
    //print_r($result); 
?> 
<field
        name="STUDENT_COURSE"
        type="sql"
        multiple="false"
        size="1"
        label="Interested In Course"
        description="COM_HELLOWORLD_FORM_DESC_UPDHELLOWORLD_GREETING"
        query="select Course_Id, Course_Name from student_course"
        key_field="Course_Id"
        value_field="Course_Name"
        default="0"
required="true"
        >
     <option value="">Please Select Course</option>
</field>

Wow, it looks to me like you are making hard work of it. 哇,在我看来,您正在努力。

Unless I am missing something, and I often do, you could simply use the right tool for the job ;) http://docs.joomla.org/SQL_form_field_type 除非我经常丢失,否则您可以简单地使用合适的工具完成工作;) http://docs.joomla.org/SQL_form_field_type

Failing that you might find another field type that will work for you. 未能找到可能适合您的其他字段类型。 http://docs.joomla.org/Standard_form_field_types http://docs.joomla.org/Standard_form_field_types

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

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