Support

Account

Home Forums ACF PRO Can\'t get the name value to use $_POST Reply To: Can\'t get the name value to use $_POST

  • Seeing the 3rd piece of code with it all together helps. When the page is being loaded and showing the form it is too late, posted data is not available when a page is being displayed. You must use an acf/save_post action https://www.advancedcustomfields.com/resources/acf-save_post/.

    This is how form submissions work
    1) You press submit
    2) ACF saves that values (this is when $_POST) is available
    3) ACF redirects back to the page and the page is reloaded ($_POST is not available when the page is being reloaded)

    If $_POST was available on the page reload then hitting the browser reload button would resubmit the data.

    
    // priority 1 or 20 depending on when you want this to run
    // if you use 1 then you need to look in $_POST['acf']
    // if you use 20 then you can use get_feild() and other acf functions
    add_action('acf/save_post', 'my_acf_save_post_action', 1);
     
    function my_acf_save_post_action($post_id) {
      if (get_post_type($post_id) != 'db_test') {
        // not our post type
        return;
      }
      // code here to get acf values and do something with them
    }