Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Created October 22, 2022 08:29
Show Gist options
  • Save aimahdi/3c01dd32b9bc24a77beb7aaea6e8965a to your computer and use it in GitHub Desktop.
Save aimahdi/3c01dd32b9bc24a77beb7aaea6e8965a to your computer and use it in GitHub Desktop.
make the dropdown field unique
add_filter('fluentform_validate_input_item_select', function ($errorMessage, $field, $formData, $fields, $form) {
$fieldName = 'dropdown'; //name attribute of the dropdown field
$target_form_id = 597; //change the form id
if($target_form_id != $form->id){ return $errorMessage; }
if ($inputValue = \FluentForm\Framework\Helpers\ArrayHelper::get($formData, $fieldName)) {
$exist = wpFluent()->table('fluentform_entry_details')
->where('form_id', $form->id)
->where('field_name', $fieldName)
->where('field_value', $inputValue)
->first();
if ($exist) {
$errorMessage = "Error ! This field needs to be unique.";
return [$errorMessage];
}
}
return $errorMessage;
}, 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment