I've got the following code. It works, the fields shows up, but there's no default value, EVER.

function entity_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'entity_node_form') {
$node = $form['#node'];
$form['contact']['entity_telnum'] = array(
'#type' => 'textfield',
'#title' => t('Tel. Number'),
'#default_value' => isset($node->entity_contacts['Tel. Num']) ? $node->entity_contacts['Tel. Num] : 'NO DEFAULT',
'#description' => t('The telephone number of the entity')
);
}

A var_dump of $node->entity_contacts['Tel. Num'] gives string(10) "0123456789"

Comments

scoutbaker’s picture

Marked http://drupal.org/node/226650 as a duplicate.

jrgns’s picture

Status: Active » Fixed

This might be because of firefox's feature were it retains form information during a refresh.

When I initialy coded the form, I didn't add a default value. I then added a default value, and pressed control-R in firefox. Because the value for the textfield was an empty string, firefox replaced the value given by drupal with the "entered" value, an empty string.

By just going to the address (control-d, enter), the default value should show up.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.