Jump to content

Creating multilanguage form fields


Moebius
 Share

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:

<?php 

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

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

    $form->add($fieldset);

    return $form->render();
?>

 

This is what I got:

1.jpg.54ee72fee0dbe61bbca834173dabb806.jpg

 

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

2.jpg.a985134321ff3c6b7d6a4a3ef66e90da.jpg

 

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...

Regards,
Sasa

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
 Share

  • Recently Browsing   0 members

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