Created
October 22, 2022 08:29
-
-
Save aimahdi/3c01dd32b9bc24a77beb7aaea6e8965a to your computer and use it in GitHub Desktop.
make the dropdown field unique
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
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