Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter("gform_pre_render", "populate_dropdown");
- add_filter("gform_admin_pre_render", "populate_dropdown");
- function populate_dropdown($form){
- //only populating drop down for form id 122
- if($form["id"] != 122)
- return $form;
- //Creating campus drop down item array.
- $zip_code = $_POST["input_16"];
- $selected_campus = $_POST["input_2"];
- $selected_degree = $_POST["input_3"];
- $campus = get_campuses_by_zipcode($selected_campus, $zip_code);
- $degree = get_degrees($selected_campus, $selected_degree);
- foreach($form["fields"] as &$field){
- //Adding campuses to drop down (field id 2)
- if($field["id"] == 2){
- $field["choices"] = $campus;
- }
- //Adding degrees to drop down (field id 3)
- if($field["id"] == 3){
- $field["choices"] = $degree;
- }
- }
- return $form;
- }
- function get_campuses_by_zipcode($selected_campus, $zip_code){
- //Develop your logic here to get the list of available campuses.
- //Make sure to mark the selected item based on the $selected_campus variable
- $campuses = array();
- $campuses[] = array("text" => "Campus A", "value" => "Campus A", "isSelected" => true);
- return $campuses;
- }
- function get_degrees($selected_campus, $selected_degree){
- //Develop your logic here to get the list of available degrees based on the selected campus.
- //Make sure to mark the selected item based on the $selected_degree variable
- $degrees = array();
- $degrees[] = array("text" => "Degree A", "value" => "Degree A", "isSelected" => true);
- return $degrees;
- }
- ?>
Add Comment
Please, Sign In to add comment