Form::set_values( array $values )

Description #

Set values for a field.

This must be called before initialization of form.

Parameters #

  • $values
    array (Required) Values.

Changelog #

VersionDescription
4.1.5Set values after form is prepared. Return current object.
4.1.0Introduced.

Source #

File: lib/class-form.php

	public function set_values( $values ) {
		if ( false === $this->prepared ) {
			$this->prepare();
		}

		if ( empty( $values ) ) {
			return $this;
		}

		foreach ( $values as $key => $val ) {
			if ( is_array( $val ) && isset( $val['value'] ) ) {
				$val = $val['value'];
			}

			$field = $this->find( $key );

			if ( $field ) {
				$field->value = $val;
			}
		}

		return $this;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment