Drupal 自定义表单安排/放置

发布于 2024-08-11 11:53:32 字数 537 浏览 4 评论 0原文

我刚刚开始使用 Drupal,但我对如何自定义“放置”所有表单元素一无所知。我通常有很多东西,就像其他人的东西一样,所以布局和美观是必须的:

alt text http://img20.imageshack.us/img20/3103/55744697.jpg

Drupal 渲染论坛的默认方式(如调查问卷(一个长水平列,有很多空格))对于我的目的来说是不可接受的。我一直在 Drupal 论坛上查找,其他几个人也有同样的问题。主要方法似乎是返回一长串 html 和 php 控件连接 - 对于我的表单来说,这太疯狂了!最简单、最干净的解决方案是什么?

有没有一种方法,就像在 ASP.NET 中使用 page.aspx/page.aspx.cs 一样,所有标记和控件都在一个文件中,而代码在另一个文件中?或者也许我可以将所有表单标记放在一个文件中,只包含占位符,并在代码中告诉 Drupal 在其占位符中渲染每个表单元素?

I am just starting out with Drupal but I am pretty clueless how to custom 'place' all of the form elements. I usually have a lot of stuff, like this other dude's thing, so placement and aesthetics are a MUST:

alt text http://img20.imageshack.us/img20/3103/55744697.jpg

Drupal's default way of rendering forums like a questionnaire (one long horizontal column with lots of spaces) are unacceptable for my purposes. I have been looking around the Drupal forums and several other people all have the same problem. The main approach seems to be to return a long concatenated string of html and php controls - for my forms, that would be insane! What is the easiest and cleanest solution to this?

Is there a way, like in ASP.NET with the page.aspx/page.aspx.cs, all the markup and controls are in one file and the code in another? Or maybe I can put all of the form markup in one file with just placeholders, and in the code, it tells Drupal to render each form elment in it's placeholder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情栀口红 2024-08-18 11:53:32

我对 Windows 不太了解,所以我无法真正理解您所做的 .NET 技术示例,但据我了解,您希望将表单的每个字段作为变量传递到页面模板中,然后能够将它们放置在 PHP 模板中...

...如果是这种情况,那么 Drupal 的行为不会那样,或者 - 更准确地说 - 它的行为不会像表单那样。表单以 HTML 形式到达页面模板,您必须使用 CSS 根据您的需要对其进行格式化。 HTML 的结构非常好,每个字段都有自己的

和一些方便的类,使主题更容易。如果这还不够,为了满足您的需求,您可以通过一系列钩子预先干预表单的生成过程。

确实,Drupal 有一个非常具体的表单API(或 FAPI) 处理表单创建、操作、验证和提交。对于新手来说这听起来可能太复杂,但 FAPI 确实是 Drupal 高度模块化设计的关键元素。

您可以查看之前的答案本周,这可能有助于您了解 FAPI 系统的核心工作原理。如果您是 Drupal 世界的新手,我建议您花一些时间阅读文档,尤其是 主题指南挂钩系统< /strong>。 Drupal 需要对其内部工作原理有相当多的了解,才能成为一个敏捷的开发平台,但“学习”投资的结果 - IMO - 非常值得付出努力。

另一方面:如果您正在努力从头开始使用表单,您可能有兴趣查看 网络表单模块(不能满足所有需求,但是一个非常常用的工具)。

HTH,欢迎来到复杂但有益的 Drupal 世界! :)

I don't know windows much, so I can't really relate to the .NET techonology example you made, but for what I understand you would expect to have each field of the form passed into the page template as variables, and then be able to place them in a PHP template...

...if this is the case, then Drupal does not behave like that, or - to be more precise - it doesn't behave like that with forms. Forms arrive to the page template as HTML and you have to use CSS to format them according to your needs. The HTML is pretty well structured, with each field in it's own <div> and a few handy classes that make theming easier. If that is not enough, for meeting your needs, you can intervene on the process generating the forms beforehand with a series of hook.

Indeed Drupal has a very specific Form API (or FAPI) to deal with form creation, manipulation, validation and submission. It might sound too complicated for a newcomer, but the FAPI is indeed a key-element to Drupal highly modular design.

You may have a look to this answer from earlier this week, as that might be useful for you to get an idea of how the FAPI system works at its core. If you are a newcomer to the world of Drupal I would suggest that you take some time for reading the documentation, especially the theming guide and the hooking system. Drupal requires to have quite some knowledge of its inner workings in order to be an agile platform to develop for, but the outcome from the investment in "studying" is - IMO - well worth the effort.

On another note: if you are struggling to start with your forms from the scratch, you might be interested in having a look to the webform module (doesn't work for all needs, but is a pretty commonly use tool).

HTH, and welcome to the complex but rewarding world of Drupal! :)

深海夜未眠 2024-08-18 11:53:32

(正如 mac 提到的),Form API 确保表单元素使用一致的格式输出:

<div id="ELEMENT-ID" class="form-item">
  <label> ... </label>
  <input type="INPUT TYPE" />
  <div class="description"> ... </div>
</div>

.. 因此,如果您想创建特定的布局,通常只需应用相关 CSS 即可。

您可以通过限制“.form-item”类的宽度并应用“float: left”来实现上面示例中的布局。不符合规则的元素总是可以单独设计。

(As mac mentions), the Form API ensures form elements are output using a consistent format:

<div id="ELEMENT-ID" class="form-item">
  <label> ... </label>
  <input type="INPUT TYPE" />
  <div class="description"> ... </div>
</div>

.. so if you want to create a specific layout, it's usually just a case of applying relevant CSS.

You could achieve the layout in the example above by limiting the width for the '.form-item' class and applying a 'float: left'. The elements which don't fit the rule, can always be individually styled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文