Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 2.00 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: Hosting Quiz Logic
  4. Plugin URI: http://www.artofblog.com
  5. Description: Custom logic for Gravity Forms Quiz
  6. Version: 1.0
  7. Author: Eric Binnion
  8. Author URI: http://ericbinnion.com
  9. */
  10.  
  11. // http://www.gravityhelp.com/forums/topic/simple-calculations
  12.  
  13. add_action('gform_pre_submission_4', 'hostQuizLogic');
  14. function hostQuizLogic($form) {
  15.  
  16.         // rgpost allows us to access each input using its id
  17.        
  18.         $technical = rgpost('input_1');
  19.         $priceRange = rgpost('input_2');
  20.         $traffic = rgpost('input_3');
  21.        
  22.         if ($traffic == 4 && $priceRange >= 3 && $technical > 1) {
  23.                 //Input 11 is used to store the name and aff link of the host we are recommending
  24.                 //Input 15 is used to describe the host and why we recommend them
  25.                 $_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/rackspace/">Rackspace</a>';
  26.                 $_POST['input_15'] = 'Rackspace';
  27.         }
  28.         else if ($priceRange >= 2 && $traffic < 4) {
  29.                 $_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/wp-engine/">WP Engine</a>';
  30.                 $_POST['input_15'] = 'WP Engine';
  31.         }
  32.         else{
  33.                 $_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/dreamhost/">Dreamhost</a>';
  34.                 $_POST['input_15'] = 'Dreamhost';
  35.         }
  36.        
  37.         /*========================================================
  38.                 This code will change the number values for each input
  39.                 back to understandable information :)
  40.         ========================================================*/
  41.        
  42.         switch ($technical) {
  43.                 case 1:
  44.                         $_POST['input_1'] = 'Beginner';
  45.                         break;
  46.                 case 2:
  47.                         $_POST['input_1'] = 'Intermediate';
  48.                         break;
  49.                 case 3:
  50.                         $_POST['input_1'] = 'Advanced';
  51.                         break;
  52.         }
  53.        
  54.         switch ($priceRange) {
  55.                 case 1:
  56.                         $_POST['input_2'] = '$0-20';
  57.                         break;
  58.                 case 2:
  59.                         $_POST['input_2'] = '$20-100';
  60.                         break;
  61.                 case 3:
  62.                         $_POST['input_2'] = '$100+';
  63.                         break;
  64.         }
  65.        
  66.         switch ($traffic) {
  67.                 case 1:
  68.                         $_POST['input_3'] = 'Low';
  69.                         break;
  70.                 case 2:
  71.                         $_POST['input_3'] = 'Moderate';
  72.                         break;
  73.                 case 3:
  74.                         $_POST['input_3'] = 'High';
  75.                         break;
  76.                 case 4:
  77.                         $_POST['input_3'] = 'Server Crashing!';
  78.                         break;
  79.         }
  80.        
  81.         return $form;
  82. }