Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.gravityhelp.com/forums/topic/database-look-up-validation
- // validate 9 digit code
- // change the 70 here to your form ID
- add_filter('gform_validation_70', 'validate_code');
- function validate_code($validation_result){
- // this assumes the code is entered in field one on your form
- // change this input_ number if it's a different field
- if(!is_code_valid($_POST['input_1'])){
- $validation_result['is_valid'] = false;
- foreach($validation_result['form']['fields'] as &$field){
- // field 1 is the field where we want to show the validation message
- if($field['id'] == 1){
- $field['failed_validation'] = true;
- $field['validation_message'] = 'The code you entered is invalid: please try again.';
- break;
- }
- }
- }
- return $validation_result;
- }
- // use this function to validate codes
- function is_code_valid($thiscode){
- // read all the codes in from the numbers.txt file
- // change the path here to the location of your file
- $codes = file('/kunden/homepages/99/d12345678/htdocs/numbers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach($codes as $code){
- // compare the entered code to all codes in the file until we find a match
- if($thiscode == $code){
- return TRUE;
- }
- }
- // if we did not have a match and are out of codes, return FALSE
- return FALSE;
- }
- // doing this here because the redirect URL does not support variables or shortcodes
- // change the 70 here to your form ID
- add_filter('gform_confirmation_70', 'valid_invitation_confirmation', 10, 4);
- function valid_invitation_confirmation($confirmation, $form, $lead, $ajax){
- // customize this URL - I send the code in the query string
- $success_url = get_bloginfo('url') . '/?code=' . $lead[1];
- $confirmation = array('redirect' => $success_url);
- return $confirmation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement