Home › Forums › Front-end Issues › Update field in user registration form
I’ve added the field supplier_user_description
to ACF in the user roles, and I’m trying to update that info when a user registers with the field key, but it’s not working.
<?php $user = update_field( 'field_6004677a93a7f', $supplier_description );?>
This is the field html:
<label>Supplier Description <span class="error">*</span></label>
<input type="text" name="supplier-description" class="text" placeholder="Enter Your Supplier Description" required />
This grabs the field values input by the user:
<?php global $reg_errors;
$reg_errors = new WP_Error;
$supplier_description=$_POST['supplier-description'];
This is on my custom registration form:
if ( 1 > count( $reg_errors->get_error_messages() ) )
{
// sanitize user form input
global $username, $useremail;
$username = sanitize_user( $_POST['username'] );
$useremail = sanitize_email( $_POST['useremail'] );
$password = esc_attr( $_POST['password'] );
$role = 'Supplier';
$userdata = array(
'user_login' => $username,
'user_email' => $useremail,
'user_pass' => $password,
'role' => $role,
);
$user = update_field( 'field_6004677a93a7f', $supplier_description );
$user = wp_insert_user( $userdata );
}
You need to supply the post ID to update_field(). See https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/
How is there a post ID if I’m registering a new user? Isn’t the ID created when the user is?
$user = wp_insert_user( $userdata );
returns the user ID. Update fields after this.
Running
$user = update_field( 'field_6004677a93a7f', $supplier_description, '$user_{$user_ID}' );
after
$user = wp_insert_user( $userdata );
Seems to break the user registration. Is running the update against the $user
variable the best way of updating the ACF field?
Thanks for your help by the way, this is most excellent of you.
$user = wp_insert_user( $userdata );
update_field('field_6004677a93a7f', $supplier_description, 'user_'.$user);
You must be logged in to reply to this topic.
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.