2015-12-18 25 views
2

你好,我需要你的幫助如果提交笨爲什麼表單輸入禁止顯示空值

我在我的控制器這樣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]'); 

請幫幫我,謝謝

回答

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

我想你可以把只讀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 
    ); 
+1

@alaamjaddou感謝我忘了'readonly'屬性我的表單輸入不錯的工作了,但如果是如何的形式是下拉?如果我使用'readonly',我仍然可以編輯下拉菜單。但是,我可以重新編輯我的問題或爲表單下拉式提出新問題? – jboxxpradhana

+1

@jboxxpradhana沒有隻讀不與下拉我的朋友我想你會使用禁用,但添加隱藏輸入到您的窗體與您的下拉輸入值 或者您可以使用jquery返回您的下拉輸入false onfocus,或你可以通過將此行添加到您的下拉式樣指針事件:無; –

+1

@alaamjaddou非常感謝 – jboxxpradhana