Support » Plugin: Advanced Custom Fields: Extended » Sending text field value to ajax request with button field

  • Resolved César Gómez

    (@cegomez)


    Hi, I’ve a text field and a button field and I want to know if is possible to send the text value to the php ajax action and how.

    Thanks,
    Cesar.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author hwk-fr

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Since the 0.8.8.5 update, other fields values are automatically passed to the Button Field Ajax Request inside the $_POST['acf'] dataset for the PHP part, and inside the data.acf object for the Javascript part. I recently updated the documentation to reflect these changes.

    You can easily access those fields values using native ACF functions get_field(), have_rows() (for repeater/flexible content) inside the acfe/fields/button hook. See documentation.

    Usage example:

    add_action('acfe/fields/button/name=my_button', 'my_acf_button_ajax', 10, 2);
    function my_acf_button_ajax($field, $post_id){
    
        // retrieve field input value 'my_field'
        $my_field = get_field('my_field');
        
        // send json success message
        wp_send_json_success("Success! My Field value is: {$my_field}");
        
    }
    

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter César Gómez

    (@cegomez)

    Hi @hwk-fr,

    Thanks for the response.

    It doesn’t work for me, I don’t know if is because I’m using it in a ACF gutenberg block.

    Any way I’ve made a workaround injecting the fields values in data object with ‘acfe/fields/button/data/name=my_button’ filter

    Regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.