John Davidson

php - Convert a text field to a selection field drop-down lists

0 comments
Message:


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.


The code is located in a PHP template of a user profile.


    <?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>


My Answer:
Sure! Here's an example of how you can convert a text field to a selection field drop-down list in PHP:

php



Replace the existing text field with the above code in your PHP template. This will create a drop-down list with the cities New York, Los Angeles, Chicago, Houston, and Miami for the user to select from.

Rate this post

3 of 5 based on 4506 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us