【问题标题】:Why form input disabled show empty value if submit codeigniter如果提交codeigniter,为什么表单输入禁用显示空值
【发布时间】:2016-03-25 00:44:47
【问题描述】:

你好,我需要你的帮助

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

请帮帮我,谢谢

【问题讨论】:

标签: php forms codeigniter validation codeigniter-3


【解决方案1】:
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 disabled,因为 disabled 不会是真的,因为它总是给空。

你应该像这样改变它:

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

【讨论】:

  • @alaamjaddou 谢谢我忘了readonly 属性我的表单输入现在很好,但是如果表单是下拉列表呢?如果我使用readonly,我仍然可以编辑下拉列表。但是我可以重新编辑我的问题或为表单下拉列表提出新问题?
  • @jboxxpradhana no readonly 不适用于下拉我的朋友,我猜你将使用禁用但使用下拉输入值向表单添加隐藏输入,或者你可以使用 jquery 返回 false onfocus下拉输入,或者您可以通过将此行添加到下拉样式指针事件中来使用您的 CSS:无;
  • @alaamjaddou 非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 2017-02-10
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
相关资源
最近更新 更多