I’m trying to add a new pages dynamically using GF_Fields::create in a gform_pre_render filter, but pagination breaks. Example below.
$pages[] = GF_Fields::create( array(
'type' => 'page',
'id' => (1000*$i),
'formId' => $form['id'],
'size' => 'large',
'visibility' => 'visible',
'displayOnly' => 1,
'pageNumber' => $i,
'nextButton' => array(
'type' => 'text',
'text' => 'Next',
'id' => (1000*$i),
),
'previousButton' => array(
'type' => 'text',
'text' => 'Previous',
'id' => (1000*$i),
),
'layoutGridColumnSpan' => 12,
) );
Then I add my new page into the form array, example below.
array_splice( $form['fields'], $position, 0, array( $pages[$i] ) );
This works in the sense that new pages are added to the web page markup if I check the HTML in the inspector. But the pagination won’t go further than the original number of pages. In this example there were originally 4 pages. Clicking next on the 4th page submits the form instead of proceeding to page 5.
I can see in the inspector that the ‘Next’ button triggers the javascript function below:
gform.submission.handleButtonClick(this)
So it’s like this javascript function isn’t aware of the new pages. Anybody know If I’m missing something?