Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created April 11, 2012 01:18
Show Gist options
  • Save ebinnion/2356113 to your computer and use it in GitHub Desktop.
Save ebinnion/2356113 to your computer and use it in GitHub Desktop.
Gravity Forms Custom Logic - AOB
<?php
/*
Plugin Name: Hosting Quiz Logic
Plugin URI: http://www.artofblog.com
Description: Custom logic for Gravity Forms Quiz
Version: 1.0
Author: Eric Binnion
Author URI: http://ericbinnion.com
*/
// http://www.gravityhelp.com/forums/topic/simple-calculations
add_action('gform_pre_submission_4', 'hostQuizLogic');
function hostQuizLogic($form) {
// rgpost allows us to access each input using its id
$technical = rgpost('input_1');
$priceRange = rgpost('input_2');
$traffic = rgpost('input_3');
if ($traffic == 4 && $priceRange >= 3 && $technical > 1) {
//Input 11 is used to store the name and aff link of the host we are recommending
//Input 15 is used to describe the host and why we recommend them
$_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/rackspace/">Rackspace</a>';
$_POST['input_15'] = 'Rackspace';
}
else if ($priceRange >= 2 && $traffic < 4) {
$_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/wp-engine/">WP Engine</a>';
$_POST['input_15'] = 'WP Engine';
}
else{
$_POST['input_11'] = '<a href="http://www.artofblog.com/recommend/dreamhost/">Dreamhost</a>';
$_POST['input_15'] = 'Dreamhost';
}
/*========================================================
This code will change the number values for each input
back to understandable information :)
========================================================*/
switch ($technical) {
case 1:
$_POST['input_1'] = 'Beginner';
break;
case 2:
$_POST['input_1'] = 'Intermediate';
break;
case 3:
$_POST['input_1'] = 'Advanced';
break;
}
switch ($priceRange) {
case 1:
$_POST['input_2'] = '$0-20';
break;
case 2:
$_POST['input_2'] = '$20-100';
break;
case 3:
$_POST['input_2'] = '$100+';
break;
}
switch ($traffic) {
case 1:
$_POST['input_3'] = 'Low';
break;
case 2:
$_POST['input_3'] = 'Moderate';
break;
case 3:
$_POST['input_3'] = 'High';
break;
case 4:
$_POST['input_3'] = 'Server Crashing!';
break;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment