It's easier done with javascript using two functions, here's a breakdown of how it all works and be patient, it's a long one
1. capitalizeWords(field)
Purpose: Automatically capitalizes the first letter of every word in a single input field.
How it works:
let value = field.value; → Gets whatever the user has typed in the field.
value.replace(/\b\w/g, c => c.toUpperCase()); → Looks for the first character of each word (\b\w) and converts it to uppercase.
field.value = value; → Puts the capitalized text back into the input field.
Example:
User types: race one
Function changes it to: Race One
2.checkRaceDuplicate(currentField)
Purpose:
Capitalizes words like capitalizeWords
Checks all 12 Race_Name fields for duplicates
Highlights duplicates and shows an inline message if found
Step-by-step:
const form = currentField.form; → Gets the form that this field belongs to.
Capitalize words in the current field (same as capitalizeWords).
Collect all 12 Race_Name fields in an array (raceFields).
Clear previous highlights and messages from all fields so old warnings disappear.
Create a map of values to fields, ignoring case (val.toLowerCase()).
Example: "Race One" and "race one" are treated as the same.
Look for any value that appears more than once in valueMap.
For each duplicate:
Add a red border around the field
Insert an inline message below it:
"This value duplicates another field. Please enter a unique value."
Example:
Race_Name_01 = Race One
Race_Name_02 = race one
The function detects a duplicate, highlights both fields, and shows messages below them.
So finally here's the code
<script>
function capitalizeWords(field) {
let value = field.value;
// Capitalize the first letter of each word
value = value.replace(/\b\w/g, c => c.toUpperCase());
field.value = value;
}
function checkRaceDuplicate(currentField) {
const form = currentField.form;
if (!form) return;
// Capitalize each word in the current field
let value = currentField.value.trim();
value = value.replace(/\b\w/g, c => c.toUpperCase());
currentField.value = value;
// Collect all Race_Name fields
const raceFields = [];
for (let i = 1; i <= 12; i++) {
const field = form.querySelector('[name="form[Race_Name_' + String(i).padStart(2, '0') + ']"]');
if (field) raceFields.push(field);
}
// Clear previous highlights and messages
raceFields.forEach(f => {
f.style.border = '';
const msg = f.nextElementSibling;
if (msg && msg.classList.contains('duplicate-msg')) msg.remove();
});
// Map values to fields (case-insensitive)
const valueMap = {};
raceFields.forEach(f => {
const val = f.value.trim().toLowerCase(); // lowercase for comparison
if (!val) return;
if (!valueMap[val]) {
valueMap[val] = [f];
} else {
valueMap[val].push(f);
}
});
// Highlight duplicates and add messages
Object.values(valueMap).forEach(fields => {
if (fields.length > 1) {
fields.forEach(f => {
f.style.border = '2px solid red';
const msg = document.createElement('div');
msg.className = 'duplicate-msg';
msg.style.color = 'red';
msg.style.fontSize = '0.9em';
msg.innerText = 'This value duplicates another field. Please enter a unique value.';
f.insertAdjacentElement('afterend', msg);
});
}
});
}
</script>
call the functions like this, in the field Race_name_01 attributes use
oninput="capitalizeWords(this);"
and in each of the other fields use
oninput="checkRaceDuplicate(this);"