我似乎找不到向Drupal模块添加CSS的方法


I can't seem to find a way to add CSS to Drupal module

我在我的项目中遇到了这个问题:我有一个Drupal模块,将ECHO长HTML代码。(我只是从Drupal模块开始)。我似乎找不到一种方法来添加CSS到这个页面。

这是我的模块:

    <?php
function kartta_help($path, $args) {
  if ($path == 'admin/help#kartta') {
    return t("<h1>kartta modulin dokumentaatio</h1>
    </br>tänne tulee karttamodulin dokumentaatio");
  }
}
function kartta_menu() {
    $items = array();
    $items['kartta_module/kartta'] = array(
        'title' => 'Karttamodule',
        'page callback' => 'say_kartta',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
     );
    return $items;
}
function say_kartta() {
echo '
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>maps form</title>
<link rel="stylesheet" href="form.css">
<script src="scripts/form.js"></script>
</head> 
<div id=header>
<h1>Form</h1>
<h2>Upload a new map or choose an existing one.</h2>
</div>
<div id=selection>
<button id=btnNew>New</button>
<button id=btnEdit>Edit</button>
</div>
<div id=new>
<br />
<form name=newMapForm action="scripts/fallback/uploadDeleteImage.php" method=POST enctype="multipart/form-data">
Choose a file to upload: <input name="map" id="inputImage" type="file" required/><br />
Give the map a name: <input type="text" name="name" id="inputName" required/> <br />
<input type="submit" value="Upload" id="btnUpload" name="upload"/>
</form>
<br />
</div>
<div id=edit>
<br />
Choose a file to edit: 
<select id=mapSelect>
</select>
<br />
<div id=afterSelect>
<p id="selectedMapName"></p>
<img alt="map" id="selectedMapImage"/>
<form name="editMapForm" action="edit.php" method="POST">
<input id="hiddenNameEdit" type="hidden" name="name" value=""/>
<input id="hiddenPathEdit" type="hidden" name="path" value=""/>
<input type="submit" value="Edit" id="btnEdit" name="edit"/>
</form>
<form name="deleteMapForm" action="scripts/fallback/uploadDeleteImage.php" method="POST" id="frmDeleteMap">
<input id="hiddenNameDelete" type="hidden" name="name" value=""/>
<input id="hiddenPathDelete" type="hidden" name="path" value=""/>
<input type="submit" value="Delete" id="btnDelete" name="delete"/>
</form>
</div>
<br />
</div>
';
}

看或读起来都不好看,但只要读开头你就明白了。.info文件:

name = kartta module
description = test module of map php ward has made
core = 7.x
stylesheets[all][] = form.css
scripts [] = scripts/form.js

1/你不需要"echo"任何东西。用"return"代替。
2/你不需要所有的"

…"部分;已经有一个模板(html.tpl.php)为您处理该部分(主题:https://drupal.org/theme-guide/6-7)
3/你应该使用表单API (https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7)而不是使用原始表单

为了回答最初的问题,这里有一个解释如何添加CSS的链接:http://adaptivethemes.com/how-to-add-css-files-in-drupal-7

可以在say_kartta()函数中使用drupal_add_css函数https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_css/7