Upates on Next Form Call
-
We are able to use the ‘action’ calls on the admin form tab actions. The calls to function.php appear to be working. The problem is that the ‘update’ to a field (field_5da06fb959057) is not showing up on the current form we are creating. The field is being updated somewhere in the background of ACF and then the next time the form is used it now has and will save that field with the prior forms ‘action’ update. If we toggle the ‘load’ fields on the form for that field (field_5da06fb959057) we see the previous forms calculated value.
If we go into the DB and call up the post-meta data the posts for this field are always one post behind. We tried doing the same action (with a different action name) before and after the ‘create post’ action but the results are the same. What are we missing (doing wrong)?
So we have actions in this order: set_final_amt, post, aft_set_final_amt
And here is our code:
//////////////////////////////////////////////////////////////
add_action(‘acfe/form/submit/action/set_final_amt’, ‘set_final_amt’, 10, 2);
function set_final_amt($form, $post_id){//Get amt fields(‘realm_select’ , ‘asgard_gift_amount’);
$realm_amt = get_field(‘realm_select’);
$asgard_amt = get_field(‘asgard_gift_amount’);
$final_amt = get_field(‘field_5da06fb959057’);// Do something in set_final_amt
if ($realm_amt[‘value’] == 0 )
{
$gift_amt = $asgard_amt * 100;
}
else
{
$gift_amt = $realm_amt[‘value’];
}$fieldkey = “field_5da06fb959057”;
$value = $gift_amt;
update_field ($fieldkey, $value);// if ( function_exists( ‘update_field’ ) ){
// update_field( $fieldkey, $gift_amount, $post_id );
// if ( isset( $_POST[‘acf’][$fieldkey] ) )
// echo ‘yoha’;
// unset($_POST[‘acf’][$fieldkey] );
// echo ‘haha’;
// }echo ‘ra’, ‘ ‘, $realm_amt[‘value’], ‘ ‘, ‘ga’, ‘ ‘, $gift_amt, ‘ ‘, ‘aa’, ‘ ‘, $asgard_amt, ‘ ‘, ‘va’, ‘ ‘, $value, ‘ ‘, ‘ca’, ‘ ‘, $final_amt;
$post_final_amt = get_field(‘field_5da06fb959057’);
echo ‘pfa’, ‘ ‘, $post_final_amt;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
add_action(‘acfe/form/submit/action/aft_set_final_amt’, ‘aft_set_final_amt’, 10, 2);
function aft_set_final_amt($form, $post_id){//Get amt fields(‘realm_select’ , ‘asgard_gift_amount’);
$realm_amt = get_field(‘realm_select’);
$asgard_amt = get_field(‘asgard_gift_amount’);
$final_amt = get_field(‘field_5da06fb959057’);// Do something in set_final_amt
if ($realm_amt[‘value’] == 0 )
{
$gift_amt = $asgard_amt * 100;
}
else
{
$gift_amt = $realm_amt[‘value’];
}$fieldkey = “field_5da06fb959057”;
$value = $gift_amt;
update_field ($fieldkey, $value);// if ( function_exists( ‘update_field’ ) ){
// update_field( $fieldkey, $gift_amount, $post_id );
// if ( isset( $_POST[‘acf’][$fieldkey] ) )
// echo ‘yoha’;
// unset($_POST[‘acf’][$fieldkey] );
// echo ‘haha’;
// }echo ‘ra’, ‘ ‘, $realm_amt[‘value’], ‘ ‘, ‘ga’, ‘ ‘, $gift_amt, ‘ ‘, ‘aa’, ‘ ‘, $asgard_amt, ‘ ‘, ‘va’, ‘ ‘, $value, ‘ ‘, ‘ca’, ‘ ‘, $final_amt;
$post_final_amt = get_field(‘field_5da06fb959057’);
echo ‘pfa’, ‘ ‘, $post_final_amt;
}
//////////////////////////////////////////////////////////////Do we need to set the priorities differently. We just used 10 and believe that your process is setting and running them by how they are ordered on the actions tab. That is why we tried both before and after ‘create post’ action.
Thank you in advance? It would be create if someone, I can’t because I do not understand it yet, made a simple flowchart diagram for ACF or ACF-ext that shows where fields/data are coming and going to during processing. Obviously our calculated field is being updated somewhere but not in our new post yet all all the other fields are pulled from current form and being used/set in the current post.
- The topic ‘Upates on Next Form Call’ is closed to new replies.