1

I have written a custom Drupal 7 module which needs to set the value of a radio button of an entityform based on a value queried from the database. I have tested hook and it is working as i am able to set a text field with in the form using:

$form['field_sem_submitter_id']['und'][0]['value']['#value'] = $user->uid;

I have tried, to no avail, to set the radio using the following and various other suggestions:

$form['field_sem_pledge_currency']['und'][0]['value']['#value'] = '2';
$form['field_sem_pledge_currency']['und'][0]['value']['#value'] = 'currency_bitcoin';
v$form['field_sem_pledge_currency']['#default_value'] = 'currency_bitcoin';

I have searched and tried numerous other suggestions on the web with no success. Any suggestions greatly appreciated.

1
  • If it is entity form then the value should get set by default, you don't need to set it. Because that is what the default behavior is.
    – Yogesh
    Nov 22, 2016 at 4:48

2 Answers 2

0

Can u please try below code:

$form['field_sem_pledge_currency']['und'][0]['#default_value']['value'] = 'currency_bitcoin';
1
  • This works ` $form['field_sem_pledge_currency']['und']['#default_value'] = 'currency_bitcoin'; ` Dec 4, 2016 at 14:38
0

I was able to set the default using:

$form['field_sem_pledge_currency']['und']['#default_value'] = 'currency_bitcoin';

Your Answer

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

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