【问题标题】:how to make array element readonly in php如何在php中使数组元素只读
【发布时间】:2021-06-29 15:04:58
【问题描述】:

您好,我试图将页面上的文本框设为只读,我尝试了我认为足够的方法,但文本框仍然可写,我仍然感到困惑,不知道我错过了什么。

我试着写

'readonly' => true,
'readonly' => 'true',
'readonly' => 'readonly',

一切都没有为我工作:(

function my_custom_checkout_field( $checkout ){

    echo '<div id="EATM_custom_checkout_field">';
    echo '<input class="EATM_checkout_exchange_rate" value="'.$this->exchange_data['EATM_exchange_rate'].'" hidden/>';
    echo sprintf('<div class="EATM_container-payments"><div class="EATM_container-image-checkout"><img src="%1$s" /></div>',$this->payment_images[ str_replace(' ','_',$this->exchange_data['EATM_payment_send_from'])  ] );
    echo "<div class='payment'>";
        woocommerce_form_field( 'my_field_name_1', array(
            'type'          => 'text',
            'class'         => array('my-field-class form-row-wide'),
            'label'         => __('ارسال'),
            'required'      =>true,
            'readonly'      =>true,
            'value'         =>$this->exchange_data['EATM_payment_send_from'],
            'placeholder'   => __('Send'),
            ), $this->exchange_data['EATM_payment_send_from']);

【问题讨论】:

    标签: php html forms woocommerce


    【解决方案1】:

    使文本框只读添加

    禁用

    喜欢这个

    <input type="text" value="1" class="form-control" disabled="">
    

    【讨论】:

    • 感谢支持,但我必须使用数组中的代码才能完成此操作,如果是 HTML 将很容易完成,但我必须使用 php 完成跨度>
    【解决方案2】:

    使用custom_attributes 标签:

    function my_custom_checkout_field( $checkout ){
    // ...
    
      woocommerce_form_field('my_field_name_1', array(
        'type' => 'text',
        'class' => array('my-field-class form-row-wide'),
        'label' => __('ارسال'),
        'required' => true,
        'custom_attributes' => ['readonly' => true], // or ['disabled' => true]
        'default' => $this->exchange_data['EATM_payment_send_from'],
        'placeholder' => __('Send'),
      ), $this->exchange_data['EATM_payment_send_from']);
    

    另外,我认为value 字段应该default 或使用最后一个参数(就像你正在做的那样)并完全删除值行。

    此处的文档:https://rudrastyh.com/woocommerce/woocommerce_form_field.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 2017-03-09
      • 2021-12-23
      • 2015-12-05
      相关资源
      最近更新 更多