Carbon_Fields\Field\Field::set_value_from_input PHP Method

set_value_from_input() public method

Load the field value from an input array based on it's name
public set_value_from_input ( array $input = null )
$input array (optional) Array of field names and values. Defaults to $_POST
    public function set_value_from_input($input = null)
    {
        if (is_null($input)) {
            $input = $_POST;
        }
        if (!isset($input[$this->name])) {
            $this->set_value(null);
        } else {
            $this->set_value(stripslashes_deep($input[$this->name]));
        }
    }

Usage Example

    /**
     * Load the field value(s) from the database.
     *
     * @param Field $field The field to retrieve value for.
     */
    public function load(Field $field)
    {
        global $wpdb;
        $value = $wpdb->get_col('
			SELECT `meta_value`
			FROM ' . $wpdb->usermeta . '
			WHERE `user_id`=' . intval($this->user_id) . '
			AND `meta_key`="' . $field->get_name() . '"
			LIMIT 1
		');
        if (!is_array($value) || count($value) < 1) {
            $field->set_value_from_input();
            return;
        }
        $field->set_value($value[0]);
    }