• Resolved mrkknnthcrz

    (@mrkknnthcrz)


    I created a Button field [https://prnt.sc/1k872dd] and use it on Theme Option [https://prnt.sc/1k84chm]

    I wanted to add a separate condition on both the “Quick Reset” and ‘Reset’ buttons.

    The ‘Reset’ button works fine, I will just add $_POST[“publish”] on my code. [https://prnt.sc/1kabipo]

    Question: What is the $_POST name of “Quick Reset”?
    (I tried the field name and field key, still don’t work)

    • This topic was modified 3 years, 7 months ago by mrkknnthcrz.
    • This topic was modified 3 years, 7 months ago by mrkknnthcrz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    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.

    Thread Starter mrkknnthcrz

    (@mrkknnthcrz)

    Hey Konrad, it works!
    Thank you so much, I love your plugin!
    Cheers!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Great to hear ??

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What is the $_POST name of Button Field?’ is closed to new replies.