Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter('gform_validation_1', 'custom_validation');
- function custom_validation($validation_result){
- global $wpdb;
- $email_field = 6;
- $form = $validation_result["form"];
- $error_message = "You can only submit a vote once every calendar day. Please come back later!";
- foreach($form["fields"] as &$field) {
- if ( $field['id'] == $email_field ) {
- $email_value = rgpost("input_{$field['id']}");
- $entry_submission = $wpdb->get_var( $wpdb->prepare(
- "SELECT lead_id FROM {$wpdb->prefix}rg_lead_detail
- WHERE form_id = %d and field_number = %d and value = %s
- ORDER BY id DESC LIMIT 1", $form['id'], $field['id'], $email_value ));
- if ( !empty( $entry_submission ) ) {
- $last_submission = $wpdb->get_var( $wpdb->prepare(
- "SELECT date_created
- FROM {$wpdb->prefix}rg_lead
- WHERE id = %d", $entry_submission ));
- if ( !empty( $last_submission ) ) {
- $time_out = date("Ymd", strtotime($last_submission) );
- $current_time = date("Ymd");
- if ( $current_time == $time_out ) {
- $validation_result['is_valid'] = false;
- $field["failed_validation"] = true;
- $field["validation_message"] = $error_message;
- continue;
- }
- }
- }
- }
- }
- $validation_result["form"] = $form;
- return $validation_result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement