Last active
May 20, 2020 02:59
-
-
Save kingjmaningo/74471391dfcfc1fea5f49c4933e0eedc to your computer and use it in GitHub Desktop.
Get value form previous page (Gravity form)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In this example im going to get certain fields that the user put in in the first page | |
// then make them choices on the second page | |
// You can paste this in your child's functions.php | |
add_filter('gform_pre_render_1', 'select_username_callback'); //only get data form form id 1 | |
function select_username_callback($form) { | |
// To get what page you are on | |
$current_page = GFFormDisplay::get_current_page($form["id"]); | |
if ($current_page == 2) { | |
// Get values from previous form | |
$value1 = rgpost( 'input_5' ); | |
$value2 = rgpost( 'input_24' ); | |
$value3 = rgpost( 'input_23' ); | |
// Get fields from current form | |
foreach($form["fields"] as &$field) { | |
// Get the specific field through its field id | |
if ($field["id"] == 27) { // Field number 27 is a radio button | |
// Store values got form previous page in an array | |
$choices = array( | |
array( 'text' => $value1, 'value' => $value1 ), | |
array( 'text' => $value2, 'value' => $value2 ), | |
array( 'text' => $value3, 'value' => $value3 ) | |
); | |
/ | |
// Store values in the raddio field | |
$field->choices = $choices; | |
$field->placeholder = 'Select a Display Name'; | |
} | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment