Jump to content

Creating multilanguage form fields


Recommended Posts

I'm trying to build custom form (module) and I want to make text fields multilanguage as they are in normal Processwire environment.

This is some of code I have:


    $form = $this->modules->get('InputfieldForm');

    $field = $this->modules->get('InputfieldText');
    $field->label = 'Title';
    $field->name = 'title';
    $field->columnWidth = 100;
    $field->required = 1;


    return $form->render();


This is what I got:



And this is what I want - with language switch at top:



Is it possible to accomplish with API?


Link to comment
Share on other sites

Evo da se i ja ukljucim, rijetko sam ovdje 😉

There you need to include FieldtypeLanguageInterface, or if you watch at TextareaLanguage, or TextLanguage you will see this part in Fieldtype class:

class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLanguageInterface {

or in TextLanguage

class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageInterface {

After that, in Inputfield part you only need to use eg. textarea or text:

class InputfieldMyNewField extends InputfieldTextarea {

Inside ___render() part you do not need to include multilanguage input because PW magic will do the rest...


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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...