Jump to content

Static translated strings and ajax forms


Recommended Posts


here is a task thats new to me. And obviously i overlook some basics. So maybe someone is so kind to give me some advice on this...

I have a page whichs collects some contact boxes straight away on page load. It is a multilanguage Site (default is in German, the screenshots shows the english version). The results are wrapped in a form, because the user is able to narrow the resulting contacts by a page reference language switcher (values are part of every contact entry)*. This is done with a javascript ajax request to avoid page reloads.

TL;DR: While everything is fine on page load, as soon as i select a country to get the related contact boxes by a ajax call, the static translated strings within the target PHP file are not recognized, e.g. their translation fails.

I assume i simply miss some basics here what and when things get parsed when doing such asynchron call.

*) The language switcher values has nothing to do with the choosen user language.

And for the brave ones...

On Page load:


The highlighted areas are static translated strings (s. below). All is fine on page load (whatever current user language).

If the user selects a country within the language switcher, the form in submitted per JS, do a ajax call and query the results by the giving value of the select option (more details s. below).

The result is valid and looks like this (here i narrowed the result to contacts related to germany):


BUT: As you can see, the static translation strings (s. highlighted areas) are not translated (e.g. use the default site language).

To give a brief overview how its done, here some excerpt screens.

Form tag with action target:




And here is the processing target PHP file (excerpt):


Many thanks in advance,







Link to comment
Share on other sites

  • olafgleba changed the title to Static translated strings and ajax forms

Hi @Zeka, many thanks for your hint! Helped me to get going.

My first guess was right,- missed something obvious ?.

Too avoid the mistake i made, this might help other forum members eventually:

As long as an file (which is used by a javascript ajax call) is not accessible to the processwire core (e.g. is a dedicated page derived from a template at least), such things as core translation etc. are not available in those files.

My approach here was to create a template, create a page from this template (with the code of my former `contacts-flatproducts.php`, s. OP) and took this page as my reference within the form action attribute.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...