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

时间:2015-12-18 10:25:22

标签: php forms codeigniter validation codeigniter-3

你好,我需要你的帮助

我的控制器中有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]');

请帮助我,谢谢

1 个答案:

答案 0 :(得分:4)

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

我认为你可以让它只读残疾,因为残疾人不会是真的因为它永远是空的。

你应该改变它:

//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
    );