【发布时间】:2017-07-08 21:58:56
【问题描述】:
我需要一些有关 PHP 版本所需属性的帮助。 必填字段可以正常工作,但问题在于 oninvalid element 以 HTML 形式显示自定义文本。
这是 HTML 版本:
<select required="" oninvalid="this.setCustomValidity('Custom TXT!')">
这是我的 PHP 版本的选择下拉框:
$options = $args['options'];
$product = $args['product'];
$attribute = $args['attribute'];
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
$class = $args['class'];
$show_option_none = $args['show_option_none'] ? true : false;
$show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options.
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
$attributes = $product->get_variation_attributes();
$options = $attributes[ $attribute ];
}
$html = '<select required="" oninvalid="this.setCustomValidity('Custom TXT!')" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '"' . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
$html .= '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
谁能帮我用这条线来显示自定义文本,现在它只给出错误。谢谢!
$html = '<select required="" oninvalid="this.setCustomValidity('Custom TXT!')"
【问题讨论】:
-
不...我在 PHP 代码中需要这个元素...
-
好吧,你必须把它转换成你的 PHP 字符串
-
@LGSon 可以帮忙吗? :))
-
如果你知道 PHP 语法,这应该很简单。我不知道,我是 .NET 开发人员
标签: php wordpress html woocommerce