Skip to content
JIX edited this page Jul 14, 2020 · 1 revision

Purpose

Text fields are probably the most common type of fields that you will use.

text-field

In Ultimate Fields text fields have various options, which let you fine-tune them to the highest degree.

Options

Placeholder text

Placeholder texts use the HTML5 placeholder attribute in order to show a grayed-out text before there is any user input.

In PHP they are managed by the set_placeholder_text( $text ) method:

Field::create( 'text', 'available_colors' )->set_placeholder_text( 'green, blue, orange' );

Prefix & Suffix

Prefixes and suffixes appear before and after the field respectively. Normally they indicate that the field is expecting a specific unit.

They are managed through the set_prefix and set_suffix methods of the field, which expect a single string parameter.

Field::create( 'text', 'price' )
	->set_prefix( '' )
	->set_sufix( '.00' )

Autocomplete suggestions

You can provide autocomplete suggestions for text fields. Ultimate FIelds uses the jQuery UI Autocomplete plugin in order to display those suggestions while users are typing.

In PHP this is done through the add_suggestions mehod, which expects an array of strings:

Field::create( 'text', 'favorite_language' )
	->add_autocomplete_suggestions( array( 'PHP', 'JavaScript', 'HTML', 'CSS' ) );

Output Settings

Value Format

In order to avoid XSS attacs, the value of text fields is formatted through the esc_html function.

In PHP, you can use the set_output_format method of the text field to choose what to use:

  • false will prevents any formatting from happening.
  • "html" will switch to using the esc_html function.
Field::create( 'text', 'subtitle' )
	->set_output_format( 'html' )
Clone this wiki locally