0

我有一个表单,我必须添加带有下拉列表的州名称字段,以便用户可以从该选择框中选择他们想要的州名称。

我怎样才能做到这一点?

4

4 回答 4

1

您可以为此使用 vtlib 库。

这就是我们如何使用 vtlib在Accounts模块中创建状态名称下拉框

<?php
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = Vtiger_Module::getInstance('Accounts');
$infoBlock = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION', $module);
$stateField = Vtiger_Field::getInstance('state', $module);
if (!$stateField) {
    $stateField = new Vtiger_Field();
    $stateField->name = 'state';
    $stateField->label = 'State';
    $stateField->columntype = 'VARCHAR(100)';
    $stateField->uitype = 16;
    $stateField->typeofdata = 'V~O';
    $infoBlock->addField($stateField);
    $stateField->setPicklistValues(array('Kerala', 'Karnataka', 'Maharashtra', 'Manipur'));

}

在该数组中添加其余状态列表。

希望这可以帮助。

于 2013-04-17T05:11:23.117 回答
1

假设你有一个像mysql这样的数据库。

  • 创建表state( state_id, state_name, state_abbr)
  • state表中获取状态(编写一个函数来获取状态)
  • 使用 php 脚本在您的选择框选项中进行迭代,例如:

    <select name="state">
    <?php
    // At this point you should have a recordset $rsstate which fetches all the records from the state table
    while($rowState = mysql_fetch_array($rsState)) { ?>
        <option value=<?php echo $rowState["state_abbr"] ?>><?php echo $rowState["state_name"]; ?></option>
    <?php } ?>
    </select>
    
于 2012-01-06T15:20:35.410 回答
0

只需转到管理面板并添加一个选项列表。它非常简单。

于 2012-06-20T05:50:39.867 回答
0

假设你有一个像mysql这样的数据库。

  • 创建表状态(state_id、state_name、state_abbr)
  • 从状态表中获取状态(编写一个函数来获取状态)
  • 使用 php 脚本示例在您的选择框选项中进行迭代:

            <select name="state">
              <?php 
                 *// At this point you should have a recordset $rsstate which fetches all the records from the state table*
                while($rowState = mysql_fetch_array($rsState)){?>
                <option value=<?php echo $rowState["state_abbr"]?>><?php echo $rowState["state_name"]; ?></option>
              <?php }?>
             </select>
    
于 2012-01-06T15:16:31.653 回答