I have made a front-end form that allows the users to set\update a few user meta fields made with Advanced Custom Fields (there are user preferences, mostly: dark\light mode, etc.).
The preferences are set through an HTML form:
<form id="cl_style_form" class="cl_style_form" action="" method="post">
<input id="cl_dark_input" name="cl_dark_input" type="hidden" value="<?php echo $cl_dark; ?>"/>
<input id="cl_compact_input" name="cl_compact_input" type="hidden" value="<?php echo $cl_compact; ?>"/>
<input id="cl_style_form_submit" name="cl_style_form_submit" type="submit"/>
</form>
and sent using the PHP Post method:
if(isset($_POST['cl_style_form_submit'])){
update_field('cl_dark', $_POST['cl_dark_input'], 'user_'.$cl_user);
update_field('cl_compact', $_POST['cl_compact_input'], 'user_'.$cl_user);
}
I am, however, encountering an issue. Whenever the submit button is pressed and the page is reloaded, the changes are not applied. Reloading the page a second time (without re-submitting the form data) applied the changes correctly.
I am not sure why this is happening.
Maybe the reload happens when the fields are still being updated?