/** * Generate the corresponding HTML for a field. * * @param array $args * * @return string */ protected function _render_specific($args) { $args = wp_parse_args($args, array('text' => false, 'extra' => array())); $options = array(); if (false !== $args['text']) { $options[] = array('value' => '', 'selected' => $args['selected'] === array('foo'), 'title' => $args['text']); } foreach ($args['choices'] as $value => $title) { $value = (string) $value; $options[] = array('value' => $value, 'selected' => $value == $args['selected'], 'title' => $title); } $opts = ''; foreach ($options as $option) { $opts .= Util::html('option', array('value' => $option['value'], 'selected' => $option['selected']), $option['title']); } $args['extra']['name'] = $args['name']; $input = Util::html('select', $args['extra'], $opts); return FormField::add_label($input, $args['desc'], $args['desc_pos']); }
/** * Given a list of fields, validate some data. * * @param array $fields List of args that would be sent to FormBuilder::input() * @param array $data (optional) The data to validate. Defaults to $_POST * @param array $to_update (optional) Existing data to populate. Necessary for nested values * * @return array */ public static function validate_post_data($fields, $data = null, $to_update = array()) { if (null === $data) { $data = stripslashes_deep($_POST); } foreach ($fields as $field) { $value = FormBuilder::get_value($field['name'], $data); $fieldObj = FormField::create($field); $value = $fieldObj->validate($value); if (null !== $value) { self::set_value($to_update, $field['name'], $value); } } return $to_update; }