0

I have a add entity form. On which I want show some fields pre-populated from other entity. I wrote form_alter hook and pre populate fields.... But for one field it wont work. It populate the data in text box but when user change that data and click on save it saves pre populated data not the changed or updated one.

Scenario 1: "field_summary_introduction" this is a text area and code used to prepopulate data is $form['field_summary_introduction']['und'][0]['#value'] = $arrDefaultEntityData['field_summary_introduction']['und'][0]['value'];

This is working fine and if user update the data it stores updated data

Scenario 2: "field_company_subtitle" this is text field and following code is not working

$form['field_company_subtitle']['und'][0]['#value'] = $arrDefaultEntityData['field_company_subtitle']['und'][0]['value'];

Instead if I use following code then it prepopulate data

$form['field_company_subtitle']['und'][0]['value']['#value'] = $arrDefaultEntityData['field_company_subtitle']['und'][0]['value'];

But not able to store updated data it stores prepopulated data.... All fields in my form taking populated data to save in db. If user update the populated data it saves old populated data in database. Thanks in advance

1 Answer 1

0

You need to use #default_value:

$form['field_company_subtitle'][LANGUAGE_NONE][0]['value']['#default_value'] = ...
1
  • Sorry not working....All fields in my form taking populated data to save in db. If user update the populated data it saves old populated data in database. Commented Mar 29, 2017 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.