Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

City field doesn't print in Message body #760

Open
germanrandhawa opened this issue Feb 26, 2024 · 1 comment
Open

City field doesn't print in Message body #760

germanrandhawa opened this issue Feb 26, 2024 · 1 comment
Labels
bug Something isn't working question Further information is requested

Comments

@germanrandhawa
Copy link

Hi,

I am using contact form 7 and added the name attribute on select as below.

Select City

Here is my Message body code:
City: [city]

  • In my inbox it prints undefined. Is it possible to print the city dropdown value in the message body
  • Also for country and state the message body prints codes instead of full names. Is it possible to print full names?

image

Copy link

dosubot bot commented Feb 27, 2024

🤖

Hey @germanrandhawa, nice to see you back! How’s everything going?

Based on the information you've provided, it seems like the issue might be related to how Contact Form 7 is processing the form data.

For the city field, make sure that the value of the selected option is being correctly set and passed when the form is submitted. The value of the selected option should be the one that appears in the email, not the attribute name. If the value is not being set correctly, it could result in "undefined" appearing in the email.

As for the country and state fields printing codes instead of full names, this is likely due to how the data is structured in the countries-states-cities-database repository. The country and state data is stored using their respective codes, not their full names.

To print the full names instead of the codes, you would need to map the codes to their corresponding names. This could be done by creating a lookup table or dictionary that maps each code to its full name, and then using this to replace the codes with their full names in the email.

Here's a simple example of how you could create such a lookup table for countries:

$countriesJson = file_get_contents("data/countries.json");
$countriesArray = json_decode($countriesJson, true);
$countryCodeToName = array();
foreach($countriesArray as $country) :
    $countryCodeToName[$country['code']] = $country['name'];
endforeach;

You could do something similar for states, but you would need to read the state data from the appropriate JSON file based on the country code.

Please note that this is a general guidance and the actual implementation might vary based on your specific setup and requirements.

As for the image you've shared, I'm sorry but I'm unable to view images. If you need to share code or error messages, please paste them as text.

Let me know if you need further clarification or assistance.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added bug Something isn't working question Further information is requested labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant