Save Link field in custom form I'm brand new at making custom forms and I'm having trouble getting the link field to save to the database.

The text body field saves fine but the link field object defined below it does not. I'm sure that this is an easy fix but I haven't been able to find proper documentation on adding the link field to custom forms.

Thanks in advance.

    /**
* Implements hook_block_configure().
*/

function My_Module_block_configure($delta='') {
$form = array();

switch($delta) {
case 'my_module' :
    // Text field form element
    $form['text_body'] = array(
        '#type' =&gt; 'text_format',
        '#title' =&gt; t('Enter your text here in WYSIWYG format'),
        '#default_value' =&gt; variable_get('text_variable', ''),
     );

     //link field
    $form['link'] = array(
        '#type' =&gt; 'link_field',
        '#size' =&gt; 20,
        '#field_name' =&gt; 'link',
    );      

    break;
}
return $form;
}

/**
* Implements hook_block_save().
*/
function My_Module_block_save($delta = '', $edit = array()) {
    switch($delta) {
    case 'my_module' :
        // Saving the WYSIWYG text
        variable_set('text_variable', $edit['text_body']['value']);
        variable_set('link_variable', $edit['link']['value']);

        break;
    }
}
I get success with this. It needs to be improved though, especially the '#language' bit. What I found to be important was to wrap the link field in a container and set '#tree' to true to group it under its key. And the link field is a multi-value field with a link title and url, so you have to take care of that.

function MYMODULE_block_configure($delta='') {
  $form = array();

  switch($delta) {
    case 'my_module' :
      // Text field form element
      $form['text_body'] = array(
        '#type' =&gt; 'text_format',
        '#title' =&gt; t('Enter your text here in WYSIWYG format'),
        '#default_value' =&gt; variable_get('text_variable', ''),
      );

      //link field
      $form['link_container'] = array(
        '#type' =&gt; 'container',
        '#attributes' =&gt; array('class' =&gt; array('some-class')),
        '#tree' =&gt; TRUE,
      );
      $form['link_container']['link'] = array(
        '#type' =&gt; 'link_field',
        '#field_name' =&gt; 'link_field',
        '#language' =&gt; 'und', // how to fix this??
        '#field_parents' =&gt; array(),
        '#delta' =&gt; 0,
        '#default_value' =&gt; array(
          'title' =&gt; variable_get('link_title', ''),
          'url' =&gt; variable_get('link_url', ''),
        ),
      );
      break;
  }
  return $form;
}

/**
 * Implements hook_block_save().
 */
function MYMODULE_block_save($delta = '', $edit = array()) {
  switch($delta) {
    case 'my_module' :
      // Saving the WYSIWYG text
      variable_set('text_variable', $edit['text_body']['value']);
      variable_set('link_title', $edit['link_container']['link']['title']);
      variable_set('link_url', $edit['link_container']['link']['url']);
      break;
  }
}