如果提交 codeigniter,为什么禁用表单输入显示空值

Why form input disabled show empty value if submit codeigniter

你好,我需要你的帮助

我的控制器有 form_input 这样的,

//getting datas from database I need to make edit form
$datas = $this->getvaluesitebyid($this->input->get('stid', TRUE));
$data['siteid'] = array(
            'name' => 'siteid',
            'type' => 'text',
            'class' => 'form-control',
            'placeholder' => 'Site ID',
            'value' => $datas['site_id_tlp'],
            'id' => 'disabledInput',
            'disabled' => '' //I set this form to be disabled
        );

在我看来,我打开了表格

<?php echo form_input($siteid); ?>

表单将被禁用,但为什么我提交时得到的是空值? 在我提交到数据库之前,我得到了 form_validation。但该表格无效,因为该值为空

这是我的规则

$this->form_validation->set_rules('siteid', 'Site ID', 'trim|required|max_length[100]');

请帮助我,谢谢

Attribute definitions

disabled [CI] When set for a form control, this boolean attribute disables the control for user input. When set, the disabled attribute has the following effects on an element:

    Disabled controls do not receive focus.
    Disabled controls are skipped in tabbing navigation.
    Disabled controls cannot be successful.

The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.

This attribute is inherited but local declarations override the inherited value.

How disabled elements are rendered depends on the user agent. For example, some user agents "gray out" disabled menu items, button labels, etc.

In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form.

<INPUT disabled name="fred" value="stone">

Note. The only way to modify dynamically the value of the disabled attribute is through a script.

See This Also

我认为你可以将它设置为只读 instedof 禁用,因为禁用不会是真的,因为它总是给出空。

你应该这样改:

//getting datas from database I need to make edit form
$datas = $this->getvaluesitebyid($this->input->get('stid', TRUE));
$data['siteid'] = array(
        'name' => 'siteid',
        'type' => 'text',
        'class' => 'form-control',
        'placeholder' => 'Site ID',
        'value' => $datas['site_id_tlp'],
        'id' => 'disabledInput',
        'readonly' => 'readonly' //I set this form to be disabled
    );