Created
          March 2, 2021 03:15 
        
      - 
      
- 
        Save rafaehlers/0e122bbd3a40b53d4533c4f895ebd03a to your computer and use it in GitHub Desktop. 
    validate_entry_before_creation
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| add_filter( 'gform_validation', 'validate_entry_before_creation', 100 ); | |
| function validate_entry_before_creation( $data ) { | |
| foreach ( $data['form']['fields'] as $field ) { | |
| if ( $field->id !== 1 ) { // replace 1 with the unique field ID | |
| continue; | |
| } | |
| $unique_id = RGFormsModel::get_field_value( $field ); | |
| // check if entry exists based on the $unique_id (e.g., passing it to https://docs.gravityforms.com/api-functions/#get-entries) | |
| if ( /* check failed */ ) { | |
| $data['is_valid'] = false; | |
| } | |
| } | |
| return $data; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment