I am building a multi-lingual website and want to localise the captions shown on buttons in a form.

<form action="check.php" method="post">
    <input class="btn btn-primary" name="action" value="Enter"/>
    <input class="btn btn-secondary" name="action" value="Cancel"/>
</form>

When I change the @value, that value is also received on the server. I would like to keep processing of the form simpler by handling only the default language server side, while still displaying the localised button names in the browser.

I tried adding an @id to the buttons and use <label> but that does not change the caption on the button itself, only adds the label next to it. From what I found about button captions it seems there is no option to do this without getting into javascript code to handle form submission. But maybe I am overlooking something.

5 Replies 5

HTML was mostly developed by English speaking developers, and they usually don't think about multiple languages. There was therefore no need for a standard way to handle multiple languages in HTML. The usual advice is to make multiple HTML pages to handle multiple languages, or use Javascript/JSON files.

However, in practice most websites supporting multiple languages do this server side, using something like PHP. There are many ways to implement this in PHP. Other server side languages like Node.js, Python, and others, can do the same.

Why not use <button> elements for buttons?

You could use a label tag and show text in Spanish. When the text in the label tag is clicked, it refers to a hidden button whose value is in English. The submit button is hidden using CSS. Below is a simple example:

enter image description here

Just to understand the question. You are using these two input elements (default is that they are text fields) as buttons, and you need the value of "action" (the name of the inputs) so that you can see if it was "Enter" or "Cancel" that was clicked when submitting the form? And then you need a localized display text for each button?

Thanks for the suggestions. It looks like there is no easy solution for what I want to do. I decided to catch the various localised values on the server and handle them as required. It limits the number of languages I can support but I prefer handling as much as possible server side instead of adding JS to the client.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.