2

Hello I need your help

I have form_input at my controller like this,

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

and at my view I open the form

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

the form is going disabled, but why if I submitting I'm getting empty value? I was give form_validation before I submitting into database. but that form goes invalid because the value is empty

this is my rules

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

Please help me, thanks

jboxxpradhana
  • 468
  • 2
  • 6
  • 22
  • Possible duplicate of [values of disabled inputs will not be submitted?](https://stackoverflow.com/questions/1355728/values-of-disabled-inputs-will-not-be-submitted) – Arth Oct 04 '18 at 17:20

1 Answers1

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

I think you could make it readonly instedof disabled, coz disabled wouldn't be true coz it give empty always.

you should change it like this :

//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
    );
Community
  • 1
  • 1
Alaa M. Jaddou
  • 1,180
  • 1
  • 11
  • 30
  • 1
    @alaamjaddou thanks I forget `readonly` attribute my form input nice work now, but how if the form is dropdown? if I use `readonly` I still can edit the dropdown. However I can re-edit my question or makes new question for form dropdown? – jboxxpradhana Dec 18 '15 at 11:16
  • 1
    @jboxxpradhana no the readonly is not working with dropdown my friend i guess you will use disabled but adding hidden input to your form with your dropdown input value or you could use the jquery to return false onfocus of your dropdown input , or you could make it with your css by adding this row to your dropdown style pointer-events: none; – Alaa M. Jaddou Dec 18 '15 at 11:23
  • 1
    @alaamjaddou Thanks a lot – jboxxpradhana Dec 18 '15 at 11:41