Hi! I’m dynamically creating a set of fields (singleproduct) from a custom post type. This works well on a single page form. But when i’m trying to do this in a multi page form (set of singleproduct fields is on page 1), it loses the fields value completely on the other coming pages and on submit. Like if they don’t exist.
I’ve stumbled upon the rpost() function, but it doesn’t make sense to me in this case.
Is there a hook i am missing or something else?
add_filter( 'gform_form_post_get_meta_1', 'populate_beers');
function populate_beers($form) {
$new_field_id = 0;
foreach( $form['fields'] as $field ) {
if( $field->id > $new_field_id ) {
$new_field_id = $field->id;
}
}
$new_field_id++;
$beers = get_posts(array(
'numberposts' => -1,
'post_status' => 'publish',
'post_type' => 'bier',
'meta_query' => array(
array(
'key' => 'ausgetrunken',
'value' => '0',
'compare' => '==' // not really needed, this is the default
)
)
));
//var_dump($beers);
foreach ( $beers as $beer ) {
// Prepare field properties
$props = array(
'id' => $new_field_id,
'type' => 'product',
'inputType' => 'singleproduct',
'label' => $beer->post_title,
'basePrice' => floatval( $beer->preis ), //2,00 €
'cssClass' => 'gf_beer',
'enableCalculation' => true,
'inputs' => array(
array(
'id' => $new_field_id.'.1',
'label' => $beer->post_title,
'name' => 'param_product'
),
array(
'id' => $new_field_id.'.2',
'label' => 'Price',
'name' => 'param_price'
),
array(
'id' => $new_field_id.'.3',
'label' => 'Quantity',
'name' => 'param_qty'
),
),
);
//var_dump($props);
// Create new gravity forms field and add it to the form object
$nf = GF_Fields::create( $props );
// Hack - insert into array at specific position
// Needed to display product fields before other fields
// in the form
array_splice( $form['fields'], 0, 0, array($nf) ); //4
$new_field_id++;
}
return $form;
}