Advertisement
willenglishiv

Gravity Forms once per day

Aug 14th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. add_filter('gform_validation_1', 'custom_validation');
  3. function custom_validation($validation_result){
  4.     global $wpdb;
  5.     $email_field = 6;
  6.     $form = $validation_result["form"];
  7.     $error_message = "You can only submit a vote once every calendar day. Please come back later!";
  8.     foreach($form["fields"] as &$field) {
  9.         if ( $field['id'] == $email_field ) {
  10.             $email_value = rgpost("input_{$field['id']}");
  11.             $entry_submission = $wpdb->get_var( $wpdb->prepare(
  12.                 "SELECT lead_id FROM {$wpdb->prefix}rg_lead_detail
  13.                 WHERE form_id = %d and field_number = %d and value = %s
  14.                 ORDER BY id DESC LIMIT 1", $form['id'], $field['id'], $email_value ));
  15.  
  16.             if ( !empty( $entry_submission ) ) {
  17.                 $last_submission = $wpdb->get_var( $wpdb->prepare(
  18.                     "SELECT date_created
  19.                     FROM {$wpdb->prefix}rg_lead
  20.                     WHERE id = %d", $entry_submission ));
  21.  
  22.                 if ( !empty( $last_submission ) ) {
  23.                     $time_out = date("Ymd", strtotime($last_submission) );  
  24.                     $current_time   = date("Ymd");
  25.  
  26.                     if ( $current_time == $time_out ) {
  27.                         $validation_result['is_valid'] = false;
  28.                         $field["failed_validation"] = true;
  29.                         $field["validation_message"] = $error_message;
  30.                         continue;
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.     }
  36.  
  37.     $validation_result["form"] = $form;
  38.     return $validation_result;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement