Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
iajay CreditAttribution: iajay commentedhttp://drupal.org/node/1647770 this might help
Comment #2
GHaddon CreditAttribution: GHaddon commentedThanks 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' ;
Comment #3
GHaddon CreditAttribution: GHaddon commentedMy bad fixed it with the following method
$form['field_company_website']['und'][0]['#default_value']['url']
Comment #4
GHaddon CreditAttribution: GHaddon commentedComment #5
GHaddon CreditAttribution: GHaddon commentedComment #5.0
GHaddon CreditAttribution: GHaddon commentedforgot to say please