If you want to correctly inflect the name of the person who fills out your form, right in the email that is automatically sent - it's easy.
First, register at https://www.sklonovani-jmen.czto have your own API key.
In the Elementor form, add a field for first or last name and the one to be inflected will be named by its ID "name".
In my case, I needed the first name in the fifth case - use the code below for this. For other variations, follow Instructions on the web or contact ChatGPT who will be happy to help you 🙂
Snippet code
Add the following code to a new snippet in the plugin Code Snippets. Don't forget to overwrite your API key in the code.
// Registering a shortcode for the fifth case without "Mrs./Mr."
function address_paty_pad_shortcode() {
// Check if the name is available in the form
if (!isset($_POST['form_fields']['name'])) {
return ''; // If the name is not available, return empty text
}
$name = sanitize_text_field($_POST['form_fields']['name']);
$pad = "5"; // We use the fifth fall to address
$klic_api = "XXXXXXXX"; // Your API key
$jmeno_url = urlencode($jname); // We escaped the name for the URL
// We call the API with a parameter to disable addressing according to the documentation
$returned_value = file_get_contents("https://www.sklonovani-jmen.cz/api?klic=$klic_api&pad=$pad&jmeno=$jmeno_url&pouzit-osloveni=ne");
// Check for API errors: if it returns a number, use universal addressing
if (is_numeric($returned_value)) {
switch ($returned_value) {
case 1:
return "Invalid API key";
case 3:
return "Exhausted API credit";
case 4:
return "Erroneous crash parameter";
case 5:
return "Missing name parameter value";
case 6:
return "Missing mandatory parameter";
case 7:
return "Invalid string in parameter nameo";
case 8:
return "Weighting"; // default addressing for legal entities
default:
return "Dear User"; // general addressing for unexpected errors
}
}
// Returns the correct form of the name if no error was found
return htmlspecialchars(1TP4Returned_value);
}
add_shortcode('address_paty_pad', 'address_paty_pad_shortcode');
Using a shortcode in an email
Now you can use the shortcode
[ address_paty_pad ]
(without spaces at brackets) in the email and will only return the first name in the correct case, for example:
Hello, [ address_paty_pad ],
thank you for your message. We will contact you as soon as possible.