【问题标题】:HTML5 event custom validation for required in PHP convertPHP转换所需的HTML5事件自定义验证
【发布时间】: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!')"

http://prntscr.com/earmll

【问题讨论】:

标签: php wordpress html woocommerce


【解决方案1】:

嗯...这是我使用普通 IDE 而不是 np++...的教训...

oninvalid="this.setCustomValidity(\'Custom TXT!\')"

关闭。

【讨论】:

  • 哈哈!我确信那些必须逃脱。很高兴你终于弄明白了。 :)
猜你喜欢
  • 2012-11-04
  • 1970-01-01
  • 2012-09-03
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
  • 1970-01-01
  • 1970-01-01
  • 2020-07-22
相关资源
最近更新 更多