欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal form drupal_get_form 增加link href 链接 有大用

shiping1 的头像

添加文本文字也是用markup 
见 /node-admin/2141

How to add custom link to drupal form / navigation using form hook



在 drupal6 中
function modulename_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'your_form_id') {  
    $form['navigation']['anyname'] = array ( '#type' => 'markup','#value' => '<a href="#">My Custom Link</a>' );
  }
}


在 drupal7 中

In Drupal 7 you can use #markup attribute, as suggested by MOLOT


/**
 * Implements hook_form_alter()
 */
function hook_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
    case 'user_login_block':
      $form['link'] = array('#markup' => l(t('Link text'),'node'));
      break;
  }
}


在 drupal7 中 的另一个示例

function batch_upload_to_do_form()
{

  $form['demo'] = array(
     '#markup' => '<div class="assets_demo"><a href="/sites/all/themes/bartik_clone/images/to_do/upload_to_do_demo.png" target="_blank" >示例</a>(必须按示例格式)
     <img src="/sites/all/themes/bartik_clone/images/to_do/upload_to_do_demo.png" /></div>
     <a href="/sites/all/themes/bartik_clone/file/to_do_demo.xls">模板</a>    
     ',
  );

  $form['upload'] = array(
     '#type' => 'file',
     '#title' => '上传excel',
     '#attributes' => array('accept' => "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  );

  $form['submit'] = array('#type' => 'submit', '#value' => '上传');
  $form['#attributes'] = array('enctype' => 'multipart/form-data');
  return $form;
}


普通分类: