Hi @vanessaflibustiers
Here is updated code but you’ll still need to make small adjustments (read below the code):
<?php
add_filter( 'forminator_field_create_input', function( $html, $attr ){
static $list_fields = [];
if( ! $list_fields ){
global $post;
$post_id = is_numeric( $post ) ? $post : $post->ID;
// get fields values from DB
$prix_adherent = get_post_meta( $post_id, 'prix-adherent', true );
$prix_non_adherent = get_post_meta( $post_id, 'prix-non-adherent', true );
// map them to form fields
$list_fields = array(
'field-1' => $price_adherent,
'field-2' => $price_non_adherent,
);
//You can add as many fields as you feel neccessary and use the post ID to get whatever custom meta data you need and add it to the array
}
if( $list_fields && isset( $list_fields[ $attr['name'] ] ) ){
$html = str_replace('value="'. $attr['value'] .'"', 'value="'. $list_fields[ $attr['name'] ] .'"', $html );
//Add data to cariable and add it to form
}
return $html;
},10, 2 );
So these lines of the code are fetching data from the database – they are reading values from your custom fields:
$prix_adherent = get_post_meta( $post_id, 'prix-adherent', true );
$prix_non_adherent = get_post_meta( $post_id, 'prix-non-adherent', true );
But you still need to change this part
'field-1' => $price_adherent,
'field-2' => $price_non_adherent,
and replace the field-1 and field-2 with IDs of the form field that should have that value from ACF added. So for example if your price fields on form are “{currency-1}” and “{currency-2}” these lines should be changed to
'currency-1' => $price_adherent,
'currency-2' => $price_non_adherent,
I hope this makes sense.
Best regards,
Adam