Skip to content

Instantly share code, notes, and snippets.

@duplaja
Last active June 20, 2019 18:23
Show Gist options
  • Save duplaja/273738c07aa954e3f5e9fd0df714ffa4 to your computer and use it in GitHub Desktop.
Save duplaja/273738c07aa954e3f5e9fd0df714ffa4 to your computer and use it in GitHub Desktop.
Sample sweepstakes for Gravity Forms
<?php
//Change gform_pre_submission_1 to gform_pre_submission_(your form # here)
add_action( 'gform_pre_submission_1', 'sweepstakes_winner_check' );
function sweepstakes_winner_check( $form ) {
//Array of codes for the first listed prize
$prize_one = array('aaaa','bbbb','cccc');
//Array of codes for second listed prize
$prize_two = array('rrrr','tttt','zzzzz');
//Add more as desired
//Change 2 to the field number the code is put into
$submitted_code = $_POST['input_2'];
$winner_or_not = 'no'; //Start off with "not a winner" by default
$prize = 'None'; //start off with "no prize" by default
if(in_array($submitted_code,$prize_one)) {
$winner_or_not 'winner';
$prize = 'A brand new car!';
}
elseif(in_array($submitted_code,$prize_two)) {
$winner_or_not = 'winner';
$prize = 'Lifetime supply of toothpaste!';
}
//Input 3 is a hidden field that stores if the person won or not
$_POST['input_3'] = $winner_or_not;
//Input 4 is a hidden field that stores the prize won
$_POST['input_4'] = $prize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment