Support

Account

Forum Replies Created

  • Excellent! Thanks for the quick reply!

  • Yeah, same here. I’ve checked everything and I think it should work. But. I’ve been working on a workaround which works for me. So let’s just close this one, maybe in the future I’ll look into this. Thanks for the support.

  • Hi John, I hope you had a nice weekend. But I’m still working on this issue. I’ve placed the code in my function.php file. But it still doesn’t work. Here is my code. I’ve replaced the code from here and pasted the code from the link you provided…

    function my_acf_save_post( $post_id ) {
    
        // get new value
        $value = get_field('voornaam_db');
    
        // do something
        echo 'data' . $value;
    }
    
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Still no value is being echo-ed. I’ve also tried to do an alert after // do somethingalert('something'); but this made the page crash after the submit.

  • Sorry, it doesn’t 😀 I have placed the function in the code just under the acf_form_head() is this possible? Or do I need to place it in the function.php file?

  • So for the way I want to use this. I’ll probably be best off using priority 20. Because I want the values after the post is submitted.

    So something like this?

    <?php// 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', 20);
    
    function my_acf_save_post_action($post_id) {
      if (get_post_type($post_id) != 'db_test') {
        // not our post type
        return;
      }
      $FirstName = get_field('voornaam_db');
        echo 'data' . $FirstName;
    }?>
  • I’ll try. But I’m repeating my self here. But maybe this will clarify.

    This is my ACF form:

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php acf_form(array(
                    'post_id'       => 'new_post',
                    'new_post'      => array(
                        'post_type'     => 'db_test',
                        'post_status'       => 'publish'
                    ),
                    'submit_value'      => 'Create a new event',
                    // 'return' => '/wp-content/themes/MY_THEME/includes/new-employee.php'
                )); ?>
            <?php endwhile; ?>
        </div>
    </div>

    It gives me this HTML

    <form id="acf-form" class="acf-form" action="" method="post">
    	<div class="acf-fields acf-form-fields -top">
    		<div id="Firstname" class="acf-field acf-field-text acf-field-5968834df2ac1 voornaam" style="width:40%;" data-name="voornaam" data-type="text" data-key="field_5968834df2ac1" data-width="40">
    			<div class="acf-label">
    				<label for="acf-field_5968834df2ac1">Voornaam</label>
    			</div>
    			<div class="acf-input">
    				<div class="acf-input-wrap"><input type="text" id="acf-field_5968834df2ac1" class="" name="acf[field_5968834df2ac1]" value="" placeholder="" /></div>	</div>
    			</div>
    		</div>
    	<div class="acf-form-submit">
    		<input type="submit" class="acf-button button button-primary button-large" value="Create a new event" />			<span class="acf-spinner"></span>			
    	</div>
    </form>

    All I want is when you click on submit it writes the entry to the WP database and returns the value of this acf[field_5968834df2ac1] field using an echo.

    Im trying to do that using this code:

    <?php
        $FirstName = $_POST['acf']['field_5968834df2ac1'];
        echo 'data' . $FirstName; ?>

    But that doesn’t give me any results. So my question was/is how do I get the value of this field when I clicked on submit and the page reloads.

    Here is my whole code:

    <?php acf_form_head(); ?>
    <?php /* Template name: Nieuwe Collega's */ get_header(); ?>
    <?php session_start();
    $_SESSION['foo'] = $_POST['acf']['field_5968834df2ac1'];
    ?>
    
    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php acf_form(array(
                    'post_id'       => 'new_post',
                    'new_post'      => array(
                        'post_type'     => 'db_test',
                        'post_status'       => 'publish'
                    ),
                    'submit_value'      => 'Create a new event',
                    // 'return' => '/wp-content/themes/intranetpuur/includes/new-employee.php'
                )); ?>
            <?php endwhile; ?>
        </div>
    </div>
    <?php
        $FirstName = $_POST['acf']['field_5968834df2ac1'];
        echo 'data' . $FirstName;
        echo $_SESSION['foo'];
     ?>
    <?php get_footer(); ?>
  • At this point, I’m just trying to echo the value if I cant do that I can load this value in my database. I’ve tried both scripts (hooks) the before and after. But I don’t know exactly how to edit those hooks so they’ll work for me…

    I’m trying to echo the value when you press submit

  • Advanced Custom Fields PRO Versie: 5.5.14

  • Hi John,

    Sorry, there was a typo in my post. I changed it but still no go. I’ve tried to figure out the acf/save_post documentation. But I can’t seem to get it to work, don’t know how.

  • I deactivated all plugin’s except ACF and now it works. Then I activated all my plugins one by one and every time I checked if the WYSIWYG fields where back to normal and after checking all one at a time it now (looks) like its working again.

    Maybe this will fix your issues as well?

Viewing 11 posts - 1 through 11 (of 11 total)