Guest User

Untitled

a guest
Jan 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2. add_filter("gform_pre_render", "populate_dropdown");
  3. add_filter("gform_admin_pre_render", "populate_dropdown");
  4.  
  5. function populate_dropdown($form){
  6.  
  7. //only populating drop down for form id 122
  8. if($form["id"] != 122)
  9. return $form;
  10.  
  11.  
  12. //Creating campus drop down item array.
  13. $zip_code = $_POST["input_16"];
  14. $selected_campus = $_POST["input_2"];
  15. $selected_degree = $_POST["input_3"];
  16.  
  17. $campus = get_campuses_by_zipcode($selected_campus, $zip_code);
  18. $degree = get_degrees($selected_campus, $selected_degree);
  19.  
  20.  
  21. foreach($form["fields"] as &$field){
  22. //Adding campuses to drop down (field id 2)
  23. if($field["id"] == 2){
  24. $field["choices"] = $campus;
  25. }
  26.  
  27. //Adding degrees to drop down (field id 3)
  28. if($field["id"] == 3){
  29. $field["choices"] = $degree;
  30. }
  31. }
  32. return $form;
  33. }
  34.  
  35. function get_campuses_by_zipcode($selected_campus, $zip_code){
  36. //Develop your logic here to get the list of available campuses.
  37. //Make sure to mark the selected item based on the $selected_campus variable
  38. $campuses = array();
  39.  
  40. $campuses[] = array("text" => "Campus A", "value" => "Campus A", "isSelected" => true);
  41. return $campuses;
  42. }
  43.  
  44. function get_degrees($selected_campus, $selected_degree){
  45. //Develop your logic here to get the list of available degrees based on the selected campus.
  46. //Make sure to mark the selected item based on the $selected_degree variable
  47. $degrees = array();
  48.  
  49. $degrees[] = array("text" => "Degree A", "value" => "Degree A", "isSelected" => true);
  50. return $degrees;
  51. }
  52.  
  53. ?>
Add Comment
Please, Sign In to add comment