Translatable Text Fields (*) > - IP.Board (IPB) News
Kanał Rss Kanał Rss
Kanał Atom Kanał Atom

Translatable Text Fields (*)

wersja drukowalna wersja Microsoft Word wersja HTML

Translatable text fields can be used to allow the user to provide a different value for all of the different languages they have on their community (if they have only one, they will appear to be a regular text field). They are commonly used for when an administrator has to provide the name for something which may need to be different depending on the language. They are not designed to be used outside of the ACP.

To use translatable fields in your code, you use the IPSHelpersFormTranslatable class within the Form Helper. Using a Translatable field is slightly more complicated than most other form types.


Creating the element

When creating the element you must provide an $options parameter specifying an application which "owns" the language string and a key. If you are displaying a "create" form for something which hasn't been created yet, you can pass NULL as the key.

Unlike other fields, $defaultValue must be NULL. The system will automatically fill in the current value for the key.

For example, the code to create your element will look something like:

$form->add( new IPSHelpersFormTranslatable( 'my_translatable_field', NULL, TRUE, array( 'app' => 'app' 'key' => 'my_language_string' ) ) );


Handling Submissions

You must save the returned value manually like so:
IPSLang::saveCustom( 'app', 'my_language_string', $values['my_translatable_field'] );


Text area and editors


You can make the field a texture rather than single-line textbook by setting the "textArea" element in $options to TRUE. To use a full WYSIWG editor, you must make all the normal considerations for an editor field. Then set the "editor" element in $options to what you would normally set as $options in the IPSHelpersFormEditor object.

czw, 01 wrzesień 2016