Turn phone number, email, or any other simple text input into a unique field. Use the input key instead of {input_key} for your input type. See the list of input keys in this link. Also, make sure the name attribute & form ID matches correctly.
For example for the phone field use this hook: fluentform/validate_input_item_phone
add_filter('fluentform/validate_input_item_{input_key}', function ($errorMessage, $field, $formData, $fields, $form) {
$fieldName = 'phone';
$target_form_id = 13;
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);
Use this code in the theme function.php file or any PHP code snippet plugin.
Feel free to share any insights or if you have a topic in mind you would like to see documentation and example code about it. For more discussion, join our Facebook group Fluent Forms Community.