Documentation

O3PO_Form

Trait for forms such as the settings form.

Tags
since
0.4.0
subpackage

O3PO/includes

author

Christian Gogolin o3po@quantum-journal.org

Table of Contents

Properties

$fields  : array<string|int, mixed>
Array of all field of the form.
$pages  : array<string|int, mixed>
Array of all pages of the form.
$plugin_name  : string
The unique identifier of this plugin.
$sections  : array<string|int, mixed>
Array of all sections of the form.
$slug  : string
Slug of this form.

Methods

checked()  : mixed
Ensure that a check box field is checked
checked_or_unchecked()  : mixed
Restrict input to checked or unchecked fields
get_field_default()  : string
Get the default value of a field by id.
get_field_defaults()  : mixed
Get the default values of all fields.
get_field_title()  : mixed
Get the title of a field by id.
get_field_value()  : mixed
Get the value of a field by id.
leave_unchanged()  : mixed
Leave user input to field unchanged.
render_array_as_comma_separated_list_field()  : mixed
Render an array as comma separated list type field.
render_checkbox_field()  : mixed
Render a checkbox type field.
render_multi_line_field()  : mixed
Render a multi line text box type field.
render_password_field()  : mixed
Render a password field.
render_select_field()  : mixed
Render a select type field.
render_single_line_field()  : mixed
Render a standard text box type field.
specify_fake_field()  : mixed
Add a fake field
specify_field()  : mixed
Specify a field of the form.
specify_page()  : mixed
Specify a section of the form.
specify_section()  : mixed
Specify a section of the form.
trim()  : mixed
Trim user input to field
trim_strip_tags()  : mixed
Trim user input to field
validate_array_as_comma_separated_list()  : mixed
Validate input to comma separated list fields.
validate_array_of_at_most_1000_checked_or_unchecked()  : mixed
Validate an array of at most 1000 values of checked or unchecked
validate_array_of_at_most_1000_names()  : mixed
Validate that an array of at most 1000 names
validate_array_of_at_most_1000_roles()  : mixed
Validate an array of at most 1000 editor coordinator or steering board entries
validate_array_of_at_most_1000_urls()  : mixed
Validate an array of at most 1000 urls
validate_array_of_at_most_1000_urls_or_empty()  : mixed
Validate an array of at most 1000 urls or empty fields
validate_array_of_at_most_1000_uuidv4s()  : mixed
Validate that an array consists of at most 1000 UUIDv4s
validate_array_of_at_most_1000_years()  : mixed
Validate that an array of at most 1000 years
validate_array_of_at_most_1000_years_or_empty()  : mixed
Validate that an array of at most 1000 years or empty
validate_doi_prefix()  : mixed
Clean user input to doi_prefix fields
validate_doi_suffix()  : mixed
Clean user input to doi_suffix fields
validate_email()  : mixed
Clean user input to email fields
validate_eprint()  : string
Clean user input to eprint fields
validate_four_digit_year()  : mixed
Clean user input to fields expecting a year.
validate_issn()  : mixed
Clean user input to issn fields
validate_issn_or_empty()  : string
Clean user input to issn fields
validate_non_negative_euros()  : mixed
Validate non-negative euro fields
validate_non_negative_float()  : mixed
Validate non-negative float
validate_positive_integer()  : mixed
Validate positive integer fields
validate_role()  : mixed
Restrict input to valid roles of people working for the journal
validate_two_letter_country_code()  : mixed
Validate two letter country code fields
validate_url()  : mixed
Clean user input to url fields
add_error()  : mixed
Record errors during input verification.

Properties

$fields

Array of all field of the form.

protected array<string|int, mixed> $fields = array()

Dictionary of all fields and their properties.

Tags
since
0.4.0
access

protected

$pages

Array of all pages of the form.

protected array<string|int, mixed> $pages = array()
Tags
since
0.4.0
access

protected

$plugin_name

The unique identifier of this plugin.

protected string $plugin_name

The string used to uniquely identify this plugin.

Tags
since
0.1.0
access

private

$sections

Array of all sections of the form.

protected array<string|int, mixed> $sections = array()

Dictionary of all sections and their properties.

Tags
since
0.4.0
access

protected

$slug

Slug of this form.

protected string $slug

Used for css classes when rendering the sections and fields. Used then storing/retreiving data from the database.

Slug of the form.

Tags
since
0.4.0
access

protected

Methods

checked()

Ensure that a check box field is checked

public checked(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
sinde

0.4.0

access

public

checked_or_unchecked()

Restrict input to checked or unchecked fields

public checked_or_unchecked(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

get_field_default()

Get the default value of a field by id.

public get_field_default(int $id) : string
Parameters
$id : int

Id of the field.

Tags
since
0.4.0
acceess

public

Return values
string —

Default value of the field

get_field_defaults()

Get the default values of all fields.

public get_field_defaults([bool $include_fake_fields = false ]) : mixed
Parameters
$include_fake_fields : bool = false

Whether to also include fake fields in the list.

Tags
since
0.4.0
acceess

public

get_field_title()

Get the title of a field by id.

public get_field_title(int $id) : mixed
Parameters
$id : int

Id of the field.

Tags
since
0.4.0
acceess

prublic

get_field_value()

Get the value of a field by id.

public abstract get_field_value(int $id) : mixed
Parameters
$id : int

Id of the field.

Tags
since
0.4.0
acceess

prublic

leave_unchanged()

Leave user input to field unchanged.

public leave_unchanged(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

render_array_as_comma_separated_list_field()

Render an array as comma separated list type field.

public render_array_as_comma_separated_list_field(string $id[, string $placeholder = null ]) : mixed

Does not escape or otherwise handle individual fields that contain commas.

Parameters
$id : string

Id of the field.

$placeholder : string = null

Placeholder text.

Tags
since
0.3.0
access

public

render_checkbox_field()

Render a checkbox type field.

public render_checkbox_field(string $id[, string $label = '' ][, bool $esc_label = true ]) : mixed
Parameters
$id : string

Id of the field.

$label : string = ''

Label of the field.

$esc_label : bool = true

Whether to escape the content of $label, disable in case you want $label to contains htmls

Tags
since
0.1.0
access

public

render_multi_line_field()

Render a multi line text box type field.

public render_multi_line_field(string $id[, int $rows = false ][, string $style = false ][, bool $preview = false ][, string $placeholder = false ]) : mixed
Parameters
$id : string

Id of the field.

$rows : int = false

Number of rows

$style : string = false

CSS style

$preview : bool = false

Whether to show a LaTeX preview below the field.

$placeholder : string = false

Placeholder

Tags
since
0.4.0
access

public

render_password_field()

Render a password field.

public render_password_field(string $id) : mixed
Parameters
$id : string

Id of the field.

Tags
since
0.1.0
access

public

render_select_field()

Render a select type field.

public render_select_field(string $id, array<string|int, mixed> $options[, string $onchange = false ][, mixed $label = '' ][, mixed $esc_label = true ]) : mixed
Parameters
$id : string

Id of the field.

$options : array<string|int, mixed>

The options between which to select

$onchange : string = false

The HTML onchange parameter

$label : mixed = ''
$esc_label : mixed = true
Tags
since
0.4.0
access

public

render_single_line_field()

Render a standard text box type field.

public render_single_line_field(string $id[, string|null $placeholder = null ][, string $autocomplete = 'on' ][, string $style = false ][, string $label = false ][, bool $esc_label = true ][, string $label_style = false ][, mixed $fallback_value = false ][, mixed $readonly = false ][, mixed $default_generator = false ]) : mixed
Parameters
$id : string

Id of the field.

$placeholder : string|null = null

Placeholder text (default is null).

$autocomplete : string = 'on'

Whether to auto complete 'on' (default) or 'off.

$style : string = false

CSS style.

$label : string = false

HTML label.

$esc_label : bool = true

Whether to escape the content of label.

$label_style : string = false

CSS style for the label.

$fallback_value : mixed = false
$readonly : mixed = false
$default_generator : mixed = false
Tags
since
0.4.0
access

public

specify_fake_field()

Add a fake field

public specify_fake_field(string $id, string $default) : mixed

Fake fields cannot be modified, but have default values that can be used to avoid hard coding values.

Parameters
$id : string

Slug-name to identify the section. Used in the 'id' attribute of tags.

$default : string

Default value for the field.

Tags
since
0.4.0
access

private

specify_field()

Specify a field of the form.

public specify_field(string $id, string $title, callable $callback, string $page, string $section, array<string|int, mixed> $args, callable $validation_callable, string $default[, int $max_length = false ]) : mixed

Keeps a record of all fields in $this->fields.

Parameters
$id : string

Slug-name to identify the field. Used in the 'id' attribute of tags.

$title : string

Formatted title of the field. Shown as the heading for the field.

$callback : callable

Function that echos out any content at the top of the field (between heading and fields).

$page : string

The slug-name of the page on which to show the field.

$section : string

The slug-name of the section in which to show the field.

$args : array<string|int, mixed>

{ Extra arguments used when outputting the field. May be an empty array().

@type string $label_for When supplied, the label will be wrapped
                        in a `<label>` element, its `for` attribute populated
                        with this value.
@type string $class     CSS Class to be added to the `<tr>` element when the
                        field is output.

}

$validation_callable : callable

Callable to use during validation of inputs. Must take a field ID and input as parameters and return a valid value for the field. Should call $this->add_error() to indicate problems.

$default : string

Default value for the field.

$max_length : int = false

Maximum length of the value of the field.

Tags
since
0.4.0
access

private

specify_page()

Specify a section of the form.

public specify_page(string $id, string $title[, callable $callback = null ]) : mixed

Keeps a record of all sections in $this->sections.

Parameters
$id : string

Slug-name to identify the page.

$title : string

Formatted title of the section. Shown as the heading for the section.

$callback : callable = null

Function that echos out the any content at the top of the page (before the first section).

Tags
since
0.4.0
access

private

specify_section()

Specify a section of the form.

public specify_section(string $id, string $title, callable $callback, string $page[, callable $summary_callback = null ]) : mixed

Keeps a record of all sections in $this->sections.

Parameters
$id : string

Slug-name to identify the section. Used in the 'id' attribute of tags.

$title : string

Formatted title of the section. Shown as the heading for the section.

$callback : callable

Function that echos out any content at the top of the section (between heading and fields).

$page : string

The slug-name of the page on which to show the section.

$summary_callback : callable = null

Callback to call when composing the summary of this form.

Tags
since
0.4.0
access

private

trim()

Trim user input to field

public trim(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

trim_strip_tags()

Trim user input to field

public trim_strip_tags(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_array_as_comma_separated_list()

Validate input to comma separated list fields.

public validate_array_as_comma_separated_list(string $id, string $input) : mixed

Break a comma separated list into an array of fields.

Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_array_of_at_most_1000_checked_or_unchecked()

Validate an array of at most 1000 values of checked or unchecked

public validate_array_of_at_most_1000_checked_or_unchecked(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_names()

Validate that an array of at most 1000 names

public validate_array_of_at_most_1000_names(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_roles()

Validate an array of at most 1000 editor coordinator or steering board entries

public validate_array_of_at_most_1000_roles(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_urls()

Validate an array of at most 1000 urls

public validate_array_of_at_most_1000_urls(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_urls_or_empty()

Validate an array of at most 1000 urls or empty fields

public validate_array_of_at_most_1000_urls_or_empty(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_uuidv4s()

Validate that an array consists of at most 1000 UUIDv4s

public validate_array_of_at_most_1000_uuidv4s(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.3
access

private

validate_array_of_at_most_1000_years()

Validate that an array of at most 1000 years

public validate_array_of_at_most_1000_years(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_array_of_at_most_1000_years_or_empty()

Validate that an array of at most 1000 years or empty

public validate_array_of_at_most_1000_years_or_empty(string $id, array<string|int, mixed> $input) : mixed
Parameters
$id : string

The id of the field whose input is validated.

$input : array<string|int, mixed>

The input.

Tags
since
0.4.1
access

private

validate_doi_prefix()

Clean user input to doi_prefix fields

public validate_doi_prefix(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.0
access

private

validate_doi_suffix()

Clean user input to doi_suffix fields

public validate_doi_suffix(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.0
access

private

validate_email()

Clean user input to email fields

public validate_email(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.0
access

private

validate_eprint()

Clean user input to eprint fields

public validate_eprint(string $id, string $input) : string
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.0
access

private

Return values
string —

Valid issn or empty string.

validate_four_digit_year()

Clean user input to fields expecting a year.

public validate_four_digit_year(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.1
access

private

validate_issn()

Clean user input to issn fields

public validate_issn(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_issn_or_empty()

Clean user input to issn fields

public validate_issn_or_empty(string $id, string $input) : string
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.0
access

private

Return values
string —

Valid issn or empty string.

validate_non_negative_euros()

Validate non-negative euro fields

public validate_non_negative_euros(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_non_negative_float()

Validate non-negative float

public validate_non_negative_float(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_positive_integer()

Validate positive integer fields

public validate_positive_integer(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_role()

Restrict input to valid roles of people working for the journal

public validate_role(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.4.1
access

private

validate_two_letter_country_code()

Validate two letter country code fields

public validate_two_letter_country_code(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

validate_url()

Clean user input to url fields

public validate_url(string $id, string $input) : mixed
Parameters
$id : string

The field this was input to.

$input : string

User input.

Tags
since
0.3.0
access

private

add_error()

Record errors during input verification.

protected abstract add_error(string $setting, string $code, string $message[, mixed $type = 'error' ]) : mixed

The O3PO_Settings class for example implements this as just a wrappter around add_settings_error().

Implementations must adhere to the following parameter specification:

Parameters
$setting : string

Slug title of the setting to which this error applies.

$code : string

Slug-name to identify the error. Used as part of 'id' attribute in HTML output.

$message : string

The formatted message text to display to the user (will be shown inside styled

and

tags).

$type : mixed = 'error'

Message type, controls HTML class. Possible values include 'error', 'success', 'warning', 'info'. Default value: 'error'


        
On this page

Search results