简体   繁体   English

将文本字段转换为选择字段下拉列表

[英]Convert a text field to a selection field drop-down lists

the following code shows a text field for the user to write their city, I would like to convert that text field into a selection field with a drop-down list.下面的代码显示了一个供用户书写城市的文本字段,我想将该文本字段转换为带有下拉列表的选择字段。 My knowledge in php is very basic, I appreciate you can help me.我在 php 方面的知识非常基础,我很感激你能帮助我。

The code is located in a PHP template of a user profile.该代码位于用户配置文件的 PHP 模板中。

    <?php
global $current_user;
wp_get_current_user();
$userID             = $current_user->ID;
$user_login         = $current_user->user_login;
$state       = get_the_author_meta( 'user_state' , $userID );
?>
<div class="row">
<div class="col-md-12">  
  <div class="couple-profile-main-block dashboard-box">
    <form id="user-profile" class="ajax-auth form-horizontal" method="post">
    <div class="status"></div>  
      <?php wp_nonce_field('ajax-user-profile-nonce', 'security'); ?>    
    <div class="row">
        <div class="col-md-6">
 
                <div class="form-group row">
                  <div class="col-sm-4"><label><?php esc_html_e('State','theme');?>*</label></div> 
                  
                  <div class="col-sm-8"><input class="form-control" id="state" name="state" type="text" value="<?php echo esc_attr($state);?>"></div> 
                
                </div>                                                          
            </div>        
        </div>

    <div class="row">
        <div class="col-md-6">
            <div class="row">
                <div class="col-sm-offset-4 col-sm-8"><button id="couple-profile-on" class="btn btn-pink"><?php esc_html_e('Update Profile','theme');?></button></div> 
            </div>        
        </div>
    </div>
    
    </form>
  </div>
</div>
</div>

You'll need to switch out that text-input to a select input - check out https://www.w3schools.com/tags/tag_select.asp您需要将该文本输入切换为选择输入 - 查看https://www.w3schools.com/tags/tag_select.asp

In your case, something like this should replace where the text input is.在您的情况下,这样的内容应该替换文本输入的位置。

<select class="form-control" id="state" name="state">
    <option value=“State1” <?php if ($state == “State1”) echo “selected”; ?>>State 1</option>

<option value=“State2” <?php if ($state == “State2”) echo “selected”; ?>>State 2</option>

<option value=“State3” <?php if ($state == “State3”) echo “selected”; ?>>State 3</option>

</select>

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

相关问题 从动态添加的行中的下拉选择中自动填充文本字段 - Auto-Populate text field from drop-down selection in dynamically added rows 根据下拉选择输入状态字段 - Input state field depending on drop-down selection 根据下拉框选择生成的值填充文本字段 - Fill a text field based on a value generated by drop down box selection 使用ajax根据下拉菜单选择更新文本字段 - Updating a text field based on Drop-down menu choice using ajax Magento Complex属性:值=(下拉项+文本字段输入),并且需要“添加其他”按钮 - Magento Complex Attribute: Value(s) = (Drop-Down item + Text Field input), and need an “Add Another” button 将 Woocmmerce 结帐页面中的邮政编码字段更改为下拉列表 - Changing Postcode field in Woocmmerce's checkout page to drop-down phpMyAdmin外键下拉字段值 - phpMyAdmin foreign key drop-down field values PHP / MSSQL在下拉列表中显示存储的字段值 - PHP/MSSQL Present stored field value in a drop-down list 出生日期字段从下拉菜单更改为日历 - Date of birth field change from drop-down to calendar 将结帐邮政编码字段自定义为自定义下拉菜单 - Customizing checkout Postcode field into a custom drop-down menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM