本文整理汇总了PHP中WPCF7_Shortcode::is_required方法的典型用法代码示例。如果您正苦于以下问题:PHP WPCF7_Shortcode::is_required方法的具体用法?PHP WPCF7_Shortcode::is_required怎么用?PHP WPCF7_Shortcode::is_required使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPCF7_Shortcode
的用法示例。
在下文中一共展示了WPCF7_Shortcode::is_required方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cf7bs_number_shortcode_handler
function cf7bs_number_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$mode = $status = 'default';
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
$class .= ' wpcf7-validates-as-number';
if ($validation_error) {
$class .= ' wpcf7-not-valid';
$status = 'error';
}
if ($tag->is_required()) {
$mode = 'required';
}
$value = (string) reset($tag->values);
$placeholder = '';
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$placeholder = $value;
$value = '';
}
if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
$value = stripslashes_deep($_POST[$tag->name]);
} elseif (isset($_GET) && array_key_exists($tag->name, $_GET)) {
$value = stripslashes_deep(rawurldecode($_GET[$tag->name]));
}
$field = new CF7BS_Form_Field(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => wpcf7_support_html5() ? $tag->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag->content, 'options' => array('min' => $tag->get_option('min', 'signed_int', true), 'max' => $tag->get_option('max', 'signed_int', true), 'step' => $tag->get_option('step', 'int', true)), 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'readonly' => $tag->has_option('readonly') ? true : false, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name));
$html = $field->display(false);
return $html;
}
示例2: wpcf7_date_validation_filter
function wpcf7_date_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$min = $tag->get_date_option('min');
$max = $tag->get_date_option('max');
$value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
if ($tag->is_required() && '' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
} elseif ('' != $value && !wpcf7_is_date($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_date');
} elseif ('' != $value && !empty($min) && $value < $min) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('date_too_early');
} elseif ('' != $value && !empty($max) && $max < $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('date_too_late');
}
if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
$result['idref'][$name] = $id;
}
return $result;
}
示例3: wpcf7_file_shortcode_handler
function wpcf7_file_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option('40');
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$atts['type'] = 'file';
$atts['name'] = $tag->name;
$atts['value'] = '1';
$atts = wpcf7_format_atts($atts);
$html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
return $html;
}
示例4: shortcode_handler
public static function shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type, 'wpcf7-date');
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option('40');
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_option('id', 'id', true);
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
$atts['type'] = 'text';
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$value = (string) reset($tag->values);
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$atts['placeholder'] = $value;
$value = '';
}
if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
$value = stripslashes_deep($_POST[$tag->name]);
}
$atts['value'] = $value;
$dpOptions = array();
$dpOptions['dateFormat'] = str_replace('_', ' ', $tag->get_option('date-format', '', true));
$dpOptions['minDate'] = $tag->get_option('min-date', '', true);
$dpOptions['maxDate'] = $tag->get_option('max-date', '', true);
$dpOptions['firstDay'] = (int) $tag->get_option('first-day', 'int', true);
$dpOptions['showAnim'] = $tag->get_option('animate', '', true);
$dpOptions['yearRange'] = str_replace('-', ':', $tag->get_option('year-range', '', true));
$dpOptions['numberOfMonths'] = (int) $tag->get_option('months', 'int', true);
$dpOptions['showButtonPanel'] = $tag->has_option('buttons');
$dpOptions['changeMonth'] = $tag->has_option('change-month');
$dpOptions['changeYear'] = $tag->has_option('change-year');
$dpOptions['noWeekends'] = $tag->has_option('no-weekends');
$inline = $tag->has_option('inline');
if ($inline) {
$dpOptions['altField'] = "#{$tag->name}_alt";
$atts['id'] = "{$tag->name}_alt";
}
$atts['type'] = $inline ? 'hidden' : 'text';
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts($atts);
$html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s %4$s</span>', $tag->name, $atts, $validation_error, $inline ? "<div id=\"{$tag->name}_datepicker\"></div>" : '');
$html = apply_filters('cf7dp_date_input', $html);
$dp_selector = $inline ? '#' . $tag->name . '_datepicker' : $tag->name;
$dp = new CF7_DateTimePicker('date', $dp_selector, $dpOptions);
self::$inline_js[] = $dp->generate_code($inline);
return $html;
}
示例5: wpcf7_number_validation_filter
function wpcf7_number_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
$min = $tag->get_option('min', 'signed_int', true);
$max = $tag->get_option('max', 'signed_int', true);
if ($tag->is_required() && '' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
} elseif ('' != $value && !wpcf7_is_number($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_number');
} elseif ('' != $value && '' != $min && (double) $value < (double) $min) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('number_too_small');
} elseif ('' != $value && '' != $max && (double) $max < (double) $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('number_too_large');
}
if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
$result['idref'][$name] = $id;
}
return $result;
}
示例6: wpcf7_textarea_validation_filter
function wpcf7_textarea_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$type = $tag->type;
$name = $tag->name;
$value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
if ($tag->is_required() && '' == $value) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
}
if (!empty($value)) {
$maxlength = $tag->get_maxlength_option();
$minlength = $tag->get_minlength_option();
if ($maxlength && $minlength && $maxlength < $minlength) {
$maxlength = $minlength = null;
}
$code_units = wpcf7_count_code_units($value);
if (false !== $code_units) {
if ($maxlength && $maxlength < $code_units) {
$result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
} elseif ($minlength && $code_units < $minlength) {
$result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
}
}
}
return $result;
}
示例7: cf7bs_file_shortcode_handler
function cf7bs_file_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$mode = $status = 'default';
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
$status = 'error';
}
// size is not used since Bootstrap input fields always scale 100%
//$atts['size'] = $tag->get_size_option( '40' );
if ($tag->is_required()) {
$mode = 'required';
}
$value = (string) reset($tag->values);
$placeholder = '';
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$placeholder = $value;
$value = '';
} elseif (empty($value)) {
$value = $tag->get_default_option();
}
if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
$value = stripslashes_deep($_POST[$tag->name]);
}
$field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => 'file', 'value' => '1', 'label' => $tag->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
$html = $field->display(false);
return $html;
}
示例8: mango_wpcf7_text_shortcode_handler
function mango_wpcf7_text_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type, 'wpcf7-text');
if (in_array($tag->basetype, array('email', 'url', 'tel'))) {
$class .= ' wpcf7-validates-as-' . $tag->basetype;
}
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts_id = '';
$atts['size'] = $tag->get_size_option('40');
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
unset($atts['maxlength'], $atts['minlength']);
}
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts_id = $atts['id'];
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = (string) reset($tag->values);
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$atts['placeholder'] = $value;
$value = '';
}
$value = $tag->get_default_option($value);
$value = wpcf7_get_hangover($tag->name, $value);
$atts['value'] = $value;
if (wpcf7_support_html5()) {
$atts['type'] = $tag->basetype;
} else {
$atts['type'] = 'text';
}
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts($atts);
if ($atts_id == 'disabledInput') {
$html = sprintf('<input %1$s disabled />%2$s', $atts, $validation_error);
} else {
$html = sprintf('<input %1$s />%2$s', $atts, $validation_error);
}
return $html;
}
示例9: wpcf7_text_validation_filter
function wpcf7_text_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
if ('text' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
}
}
if ('email' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
} elseif ('' != $value && !wpcf7_is_email($value)) {
$result->invalidate($tag, wpcf7_get_message('invalid_email'));
}
}
if ('url' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
} elseif ('' != $value && !wpcf7_is_url($value)) {
$result->invalidate($tag, wpcf7_get_message('invalid_url'));
}
}
if ('tel' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
} elseif ('' != $value && !wpcf7_is_tel($value)) {
$result->invalidate($tag, wpcf7_get_message('invalid_tel'));
}
}
if (!empty($value)) {
$maxlength = $tag->get_maxlength_option();
$minlength = $tag->get_minlength_option();
if ($maxlength && $minlength && $maxlength < $minlength) {
$maxlength = $minlength = null;
}
$code_units = wpcf7_count_code_units($value);
if (false !== $code_units) {
if ($maxlength && $maxlength < $code_units) {
$result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
} elseif ($minlength && $code_units < $minlength) {
$result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
}
}
}
return $result;
}
示例10: _hw_wcpf7_country_field_shortcode
/**
* render wpcf7 field for counties
* @param $tag
*/
function _hw_wcpf7_country_field_shortcode($tag)
{
if (!is_array($tag)) {
return '';
}
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$multiple = $tag->has_option('multiple');
$include_blank = $tag->has_option('include_blank');
$first_as_label = $tag->has_option('first_as_label');
//$values = $tag->values;
$values = array('0' => 'Select country');
$values = array_merge($values, hw_wpcf7_field_countries_data());
$labels = $tag->labels;
$html = '';
foreach ($values as $key => $value) {
$item_atts = array('value' => $value);
$item_atts = wpcf7_format_atts($item_atts);
$label = isset($labels[$key]) ? $labels[$key] : $value;
$html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
}
if ($multiple) {
$atts['multiple'] = 'multiple';
}
$atts['name'] = $tag->name . ($multiple ? '[]' : '');
$atts = wpcf7_format_atts($atts);
$html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
return $html;
}
示例11: wpcf7_text_validation_filter
function wpcf7_text_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
if ('text*' == $tag->type) {
if ('' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
}
}
if ('email' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
} elseif ('' != $value && !wpcf7_is_email($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_email');
}
}
if ('url' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
} elseif ('' != $value && !wpcf7_is_url($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_url');
}
}
if ('tel' == $tag->basetype) {
if ($tag->is_required() && '' == $value) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_required');
} elseif ('' != $value && !wpcf7_is_tel($value)) {
$result['valid'] = false;
$result['reason'][$name] = wpcf7_get_message('invalid_tel');
}
}
if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
$result['idref'][$name] = $id;
}
return $result;
}
示例12: wpcf7_textarea_shortcode_handler
function wpcf7_textarea_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['cols'] = $tag->get_cols_option('');
$atts['rows'] = $tag->get_rows_option('');
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_option('id', 'id', true);
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = (string) reset($tag->values);
if ('' !== $tag->content) {
$value = $tag->content;
}
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$atts['placeholder'] = $value;
$value = '';
}
if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
$value = stripslashes_deep($_POST[$tag->name]);
}
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts($atts);
$html = sprintf('<textarea %2$s></textarea>', $tag->name, $atts, esc_textarea($value), $validation_error);
return $html;
}
示例13: wpcf7_textarea_shortcode_handler
function wpcf7_textarea_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['cols'] = $tag->get_cols_option('40');
$atts['rows'] = $tag->get_rows_option('10');
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = (string) reset($tag->values);
if ('' !== $tag->content) {
$value = $tag->content;
}
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$atts['placeholder'] = $value;
$value = '';
}
$value = wpcf7_get_hangover($tag->name, $value);
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts($atts);
$html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
return $html;
}
示例14: wpcf7_birthday_shortcode_handler
function wpcf7_birthday_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type, 'wpcf7-birthday');
if ($validation_error) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option('5');
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
if ($tag->has_option('readonly')) {
$atts['readonly'] = 'readonly';
}
if ($tag->is_required()) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = (string) reset($tag->values);
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
$atts['placeholder'] = $value;
$value = '';
} elseif ('' === $value) {
$value = $tag->get_default_option();
}
$value = wpcf7_get_hangover($tag->name, $value);
$atts['value'] = $value;
$atts['type'] = 'text';
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts($atts);
$html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
return $html;
}
示例15: cf7bs_select_shortcode_handler
function cf7bs_select_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$mode = $status = 'default';
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
$status = 'error';
}
if ($tag->is_required()) {
$mode = 'required';
}
$defaults = array();
$default_choice = $tag->get_default_option(null, 'multiple=1');
foreach ($default_choice as $value) {
$key = array_search($value, $values, true);
if (false !== $key) {
$defaults[] = (int) $key + 1;
}
}
if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
$defaults = explode('_', $matches[1]);
}
$defaults = array_unique($defaults);
$multiple = $tag->has_option('multiple');
$include_blank = $tag->has_option('include_blank');
$first_as_label = $tag->has_option('first_as_label');
$values = $tag->values;
$labels = $tag->labels;
if ($data = (array) $tag->get_data_option()) {
$values = array_merge($values, array_values($data));
$labels = array_merge($labels, array_values($data));
}
$empty_select = empty($values);
$shifted = false;
if ($empty_select || $include_blank) {
array_unshift($labels, '---');
array_unshift($values, '');
$shifted = true;
} elseif ($first_as_label) {
$values[0] = '';
}
$options = array();
$selected = '';
if ($multiple) {
$selected = array();
}
if (isset($_POST[$tag->name])) {
$post = $_POST[$tag->name];
} else {
if (isset($_GET[$tag->name])) {
if ($multiple) {
$get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
} else {
$get = rawurldecode($_GET[$tag->name]);
}
}
$post = $multiple ? array() : '';
}
$posted = wpcf7_is_posted();
foreach ($values as $key => $value) {
$options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
if ($posted && !empty($post)) {
if ($multiple && in_array(esc_sql($value), (array) $post)) {
$selected[] = $value;
}
if (!$multiple && $post == esc_sql($value)) {
$selected = $value;
}
} elseif (isset($get) && !empty($get)) {
if ($multiple && in_array(esc_sql($value), (array) $get)) {
$selected[] = $value;
}
if (!$multiple && $get == esc_sql($value)) {
$selected = $value;
}
} elseif (!$shifted && in_array((int) $key + 1, (array) $defaults) || $shifted && in_array((int) $key, (array) $defaults)) {
if ($multiple) {
$selected[] = $value;
} else {
$selected = $value;
}
}
}
$field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => $multiple ? 'multiselect' : 'select', 'value' => $selected, 'label' => $tag->content, 'options' => $options, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
$html = $field->display(false);
return $html;
}