Hello,
Thanks for the feedback!
The Button field will use the field key as name
like any other ACF field. You can see that when inspecting the button with your browser inspector. See screenshot: https://i.imgur.com/fKRrE6U.png.
In this example, the button will be set as $_POST['acf']['field_610e7fa6851d4'] = 'Reset'
when using the acf/save_post
hook, for example. Please note that the button name/value pair will be only set in the $_POST
dataset if the user click on it to submit the form, following the HTML form button submission specifications.
Usage example:
add_action('acf/save_post', 'my_acf_save_post');
function my_acf_save_post($post_id){
// retrieve $_POST['acf']
$acf = acf_maybe_get_POST('acf', array());
// user clicked on my_reset button
// also works: isset($_POST['acf']['field_610e7fa6851d4'])
if(acf_maybe_get($acf, 'field_610e7fa6851d4')){
// do something...
}
}
If you prefer to interact with field name instead of the field key, you can use the acfe/save_option
hook (as you’re on an options page). This ACF Extended hook is an enhanced version of the native acf/save_post
and allow you to interact with the $_POST
directly by using get_field('my_field')
, have_rows('my_repeater')
etc… See documentation.
Usage example:
add_action('acfe/save_option', 'my_acfe_save_options_page', 10, 2);
function my_acfe_save_options_page($post_id, $object){
// retrieve 'reset' button
$my_reset = get_field('my_reset');
// user clicked on my_reset button
if($my_reset){
// do something...
}
}
Hope it helps!
Have a nice day!
Regards.