Home › Forums › Front-end Issues › Front End User Profile Edit – Selection Field
Ok I’ve been trying lots of things but no success yet.
I have a Front End User Profile Editing page on my site. One of the fields is a selection list. I have no problem editing & updating text fields for the user, so at least I have that part working.
OBJECTIVE:
1.) I need the selection list to show the choice values I have set up in ACF
2.) I need the value selected by the user to be saved
3.) Upon the user returning, I need the saved choice to be shown in the selection field.
I am able to display the current value picked by the user like this:
<?php the_author_meta( 'customer_type', $current_user->ID ); ?>
But, that’s only when I save something from inside the backend. Which is not ideal.
I have also tried this, but it returns nothing for me:
<?php
$field = get_field_object('field_56aba9ca0d64a', $current_user->ID);
$value = get_field('customer_type', $current_user->ID);
$label = $field['choices'][ $value ];
?>
<p>Color: <?php echo $label; ?></p>
Right now, I just have HTML hard coded in there as a place holder. Here is a screenshot of the user editing page.
Hi @juiceex
Could you please provide me the code to show the form?
To show the custom field value of a user, please take a look at this page: http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/.
I hope this helps. Thanks!
Sure thing! I have trimmed it down to just the important parts I think. You’ll see that I just have it hardcoded in there at the moment. I’m not sure how to display it dynamically, or SAVE the users choice.
<?php
/*
Template Name: Video Set Up Page
*/
acf_form_head();
/* Get user info. */
global $current_user, $wp_roles;
?>
<!-- START THE CUSTOM SECTION -->
<div id="post-218">
<form method="post" id="adduser" action="<?php the_permalink(); ?>">
<div id="acf-form-data" class="acf-hidden">
<input type="hidden" name="_acfnonce" value="87d0486349" />
<input type="hidden" name="_acfchanged" value="0" />
</div>
<!-- START VIDEO SET UP SECTION -->
<label for="email">Customer Type</label>
<select id="acf-field_56aba9ca0d64a" class="" name="acf[field_56aba9ca0d64a]" data-ui="0" data-ajax="0" data-multiple="0" data-placeholder="Select" data-allow_null="0" style="width: 100%;">
<option value="Customer">Customer</option>
<option value="Member">Member</option>
<option value="Client">Client</option>
<option value="Patient">Patient</option>
<option value="Guest">Guest</option>
<option value="Subscriber">Subscriber</option>
</select>
<input type="hidden" name="wlm_updating_profile" value="1" />
<script type="text/javascript">
function MoveWLMember(){
try{
var x=document.getElementById('WishListMemberUserProfile');
var p=x.parentNode;
var s=p.getElementsByTagName('h3');
p.insertBefore(x,s[0]);
}catch(e){}
}
MoveWLMember();
</script>
<p class="form-submit">
<input name="updateuser" type="submit" id="updateuser" class="submit button" value="Update Your Information" />
<input type="hidden" id="_wpnonce" name="_wpnonce" value="c3b5a2056a" /><input type="hidden" name="_wp_http_referer" value="/success/" />
<input name="action" type="hidden" id="action" value="update-user" />
</p><!-- .form-submit -->
</form><!-- #adduser -->
</div><!-- .entry-content -->
<!-- END OF THE CUSTOM SECTION -->
Hi @juiceex
ACF has acf_form() function to show the form automatically. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/create-a-front-end-form/.
So you can add a form like this:
acf_form(array('post_id' => 'user_' . get_current_user_id()));
I hope this helps.
The topic ‘Front End User Profile Edit – Selection Field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.