Home › Forums › Front-end Issues › How update custom field checkbox ACF in user profile from front end › Reply To: How update custom field checkbox ACF in user profile from front end
Hi, @locomo i solved it,
1) in custom form front end:
<form id="your-profile" class="nice" action="<?php echo get_edit_profile_url() ?>" method="POST" />
<?php
global $current_user;
$allCheckbox = get_field('newsletter_preferences','user_'.$current_user->ID);
$field_data = get_field_object('your_field_key');
$field_key = $field_data['key'];
$field = get_field_object($field_key, 'user_'.$current_user->ID);
?>
<input type="hidden" value="<?php echo 'acf['.$field['key'].']' ?>"/>
<?php
foreach($field['choices'] as $key => $label){
if(is_array($allCheckbox) && in_array($key, $allCheckbox)){
$checked = 'checked';
} else {
$checked = '';
}
echo '<p class="field"><input type="checkbox" '.$checked.' name="acf['.$field['key'].'][]" value="'.$key.'">'.$label.'</p>';
}
?> </form>
2) in funtions.php
function update_extra_profile_fields($user_id) {
global $current_user;
$newsletterOptions = isset( $_POST['acf']['your_field_key'] ) ? $_POST['acf']['your_field_key'] : null;
$f_id = update_field( 'your_field_key', $newsletterOptions , 'user_'.$user_id);
}
add_action('personal_options_update', 'update_extra_profile_fields');
</form>
this must work so that you can update the fields in the user dahsboard from the custom form.
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.