We have a custom module using hook_form_alter which sets the default values of fields in a content type, the code below which works for other fields doesn't work for the link field.

$form['field_company_name']['und'][0]['value']['#default_value'] = $value;

we tried using ['url'] instead of ['value'] but this doesn't seem to work.

Can someone please help with this.

Comments

iajay’s picture

GHaddon’s picture

Thanks for the reply but unfortunately still cant get it to work

<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.

$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' ;

GHaddon’s picture

My bad fixed it with the following method
$form['field_company_website']['und'][0]['#default_value']['url']

GHaddon’s picture

Status: Active » Fixed
GHaddon’s picture

Status: Fixed » Closed (fixed)
GHaddon’s picture

Issue summary: View changes

forgot to say please