i found, that after submiting form, items that are #disabled are not present in $form_state['values'].
but i need it. variant of making textfield (in my case) editable cant be taken.

Comments

zythar’s picture

i found that i can get needed value by using $form['my_field']['#default_value'] but i dont think that it is right..

justageek’s picture

Create hidden fields with the values you really want, and make your non-editable textfields with different names, so they show but you don't need them.

Other than that, not sure, I think if you make it disabled, the value does not come through.

Another alternative is to use jquery to make it disable after rendering rather than doing it in Drupal form definitions, but that is subject to visitors having javascript on.

zythar’s picture

i used variant with hidden fields. thanks very much.
its funny that i couldnt come to that myself...

j_ten_man’s picture

Careful with hidden values. They can be modified using javascript. Your first solution is safer. Or, if you like the hidden solution then make them of type 'value':

$form['hidden-value'] = array(
  '#type' => 'value',
  '#value' => 'value to pass',
);
justageek’s picture

You should always still validate your data to make sure it is what you expect, even when you try to prevent the user from modifying the value.

marthinal’s picture

i had exactly the same but i can do it using a textarea put rows to 1 and i dont know why i dont lose my data in validations ..... i was checking and D7 had the same

The only source of knowledge is experience. ~ Albert Einstein.