The link field seems to work fine without a default value:

<input id="edit-field-fieldgroup-und-0-field-web-site-link-und-0-url" class="fluid form-text" type="text" maxlength="2048" size="" value="" name="field_fieldgroup[und][0][field_web_site_link][und][0][url]">

But when I use a hook_form_alter() to set a default value, the form field breaks:

<?php
$form['field_fieldgroup']['und'][0]['field_web_site_link']['und'][0]['#default_value'] = 'http://www.example.com';
?>

The size is blank and the value only has the first character:

<input id="edit-field-fieldgroup-und-0-field-web-site-link-und-0-url" class="fluid form-text" type="text" maxlength="2048" size="" value="h" name="field_fieldgroup[und][0][field_web_site_link][und][0][url]">

Comments

stevenc’s picture

This field has sub-components, so you need to set the 'url' index for it:

<?php
$form['field_fieldgroup']['und'][0]['field_web_site_link']['und'][0]['#default_value']['url'] = 'http://www.example.com';
?>
ghaddon’s picture

I am also having a similar problem with adding a default value.

http://drupal.org/node/1782516

<input id="edit-field-company-website-und-0-url" class="form-text" type="text" maxlength="2048" size="60" value="" name="field_company_website[und][0][url]">

I have tried all the following code but to no avail.

<?php
$form['field_company_website']['und'][0]['url']['#default_value']['url'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['#default_value']['url'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['url']['#default_value'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['#default_value'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['value']['url']['#default_value']['url'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['url']['value']['#default_value']['url'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['value']['url']['#default_value'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['url']['value']['#default_value'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['value']['#default_value']['url'] = 'http://www.example.com' ;
$form['field_company_website']['und'][0]['value']['#default_value'] = 'http://www.example.com' ;
?>

If you found a solution it would be greatly appreciated

ghaddon’s picture

I fixed the problem

$form['field_company_website']['und'][0]['#default_value']['url'] = "url"

Thanks

ghaddon’s picture

Status: Active » Closed (fixed)