Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafaehlers/0e122bbd3a40b53d4533c4f895ebd03a to your computer and use it in GitHub Desktop.
Save rafaehlers/0e122bbd3a40b53d4533c4f895ebd03a to your computer and use it in GitHub Desktop.
validate_entry_before_creation
<?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