Moebius

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:

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

 

Share this post


Link to post
Share on other sites

dobro vece 🙂

I think you'll have to define your input field as type "TextareaLanguage" or "TextLanguage".

And in your module use something like 

$field->label = _('Title');

 

  • Like 1

Share this post


Link to post
Share on other sites

dobro vece dragane 🙂

however, still no language switch at top.

also tried with:

$field->type = new FieldtypeTextLanguage();

but with no success.

Share this post


Link to post
Share on other sites

Perhaps you'll need to uninstall and reinstall your module. Or click at the bottom button in modules > clear compiled files, to see your changes.

Share this post


Link to post
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

Share this post


Link to post
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.