[英]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.