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 7 digit code
- // change the 3 here to your form ID
- add_filter('gform_validation_3', '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($csvdata, $id, $_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 ABC ID you entered is invalid: please try again.';
- break;
- }
- }
- }
- return $validation_result;
- }
- // This creates the array from the data file in the fuction below
- function csv_in_array($url,$delm=";",$encl="\"",$head=false) {
- $csvxrow = file($url); // ---- csv rows to array ----
- $csvxrow[0] = chop($csvxrow[0]);
- $csvxrow[0] = str_replace($encl,'',$csvxrow[0]);
- $keydata = explode($delm,$csvxrow[0]);
- $keynumb = count($keydata);
- if ($head === true) {
- $anzdata = count($csvxrow);
- $z=0;
- for($x=1; $x<$anzdata; $x++) {
- $csvxrow[$x] = chop($csvxrow[$x]);
- $csvxrow[$x] = str_replace($encl,'',$csvxrow[$x]);
- $csv_data[$x] = explode($delm,$csvxrow[$x]);
- $i=0;
- foreach($keydata as $key) {
- $out[$z][$key] = $csv_data[$x][$i];
- $i++;
- }
- $z++;
- }
- }
- else {
- $i=0;
- foreach($csvxrow as $item) {
- $item = chop($item);
- $item = str_replace($encl,'',$item);
- $csv_data = explode($delm,$item);
- for ($y=0; $y<$keynumb; $y++) {
- $out[$i][$y] = $csv_data[$y];
- }
- $i++;
- }
- }
- return $out;
- }
- // This calls the abcid.txt file and sends it to the processor function above
- $csvdata = csv_in_array( "/home/abcid.txt", ";", "\"", true );
- // This searches the array also making another array of just the abcid values
- $id = 'abcid';
- function is_code_valid($csvdata, $id, $thiscode) {
- $results = array();
- is_code_valid_r($array, $key, $value, $results);
- if($thiscode == $results[0]['#value']) {
- return TRUE;
- }
- // if we did not have a match and are out of codes, return FALSE
- return FALSE;
- }
- // This is the secondary array
- function is_code_valid_r($array, $key, $value, &$results) {
- if (!is_array($array))
- return;
- if ($array[$key] == $value)
- $results[] = $array;
- foreach ($array as $subarray)
- is_code_valid_r($subarray, $key, $value, $results);
- }
- // doing this here because the redirect URL does not support variables or shortcodes
- // change the 3 here to your form ID
- add_filter('gform_confirmation_3', '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 = 'www.example.com/registration-step-2/?abcid=' . $lead[1];
- $confirmation = array('redirect' => $success_url);
- return $confirmation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement