Drupal 视图 - 可以分割公开的形式吗?

发布于 2024-11-18 05:47:46 字数 189 浏览 12 评论 0原文

我需要在页面的侧边栏中显示公开表单的一部分,并在 $content 区域中显示表单和内容的其余部分。我真的找不到好的方法来做到这一点。我通过设置“公开形式”设置的“块”视图,然后尝试仅通过 .tpl 文件显示我需要的部分来以某种方式显示它。问题是,当单击提交按钮时(提交按钮位于 $content 区域),侧边栏中的过滤器不会被考虑在内。

I need to display part of the exposed form in my page's sidebar, and the rest of the form and content in the $content area. There's really no good way that I can find to do this. I sort of got it to show up in a way by making a "block" view with "exposed form" set and then trying to only show the part that i needed through .tpl files. The problem is that then, when the submit button is clicked (the submit button is in the $content area), then the filters that are in the sidebar are not taken into account.

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

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

发布评论

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

评论(6

情感失落者 2024-11-25 05:47:46

一些横向思考...为什么不探索纯 CSS 选项呢?您可以使用 position:absolute 放置该表单元素吗?或者(考虑是右侧边栏)float:right 然后一些负的右边距将其推到侧边栏?如果您使用 960 网格系统,请使用 pullpush 类。

Some lateral thinking... Why not explore CSS-only options? You can place that form element playing with position:absolute ? Or (considering is a right-sidebar) float:right and then some negative right margin to push it to the sidebar? If you are using 960 grid system, play with pull and push classes.

心凉怎暖 2024-11-25 05:47:46

首先我将回答你的问题,然后我将解释你为什么问错误的问题:

如果你在 formapi 之外构建表单,你可能会运气好。这会变得很糟糕,并且需要您对攻击向量(例如批量分配)格外小心。

views_some_view.tpl.php

<form name="input" action="/link/to/view" method="get">
  Country: <input type="text" name="country" />

my_custom_expose_view.module:hook_block()
城市:

这将创建一个表单,在大多数情况将以

开头,有一些输入字段,然后有很多随机HTML,然后是一些更多的输入字段,然后是结束的 .

您可能知道, 只会发布它所包含的 form 标记的所有内容。以下 HTML 中的提交按钮:

<form name="input_1" action="/link/to/view" method="get">
  Country: <input type="text" name="country" />
</form>
<form name="input_2" action="/link/to/view" method="get">
  City: <input type="text" name="city" />
  <input type="submit" value="Submit" />
</form>

将仅发送 City。这些不是您正在寻找的机器人。

它需要是一个大表单,但由于 form/form 之间的所有内容都非常动态,并且包含大量 HTML,包括潜在的其他表单,因此确实不是你想要的。此外:块外观(显示/未显示)的控制完全独立于内容。您将需要大量可靠的代码来确保块 a) 当起始 form 标签不存在时永远不会显示,并且 b) 保证在打开 form 时显示块 标签存在。否则,您不仅拥有无效的 HTML,而且还拥有损坏的 HTML,这将真正导致您的页面在大多数情况下无法使用。

您根本不希望表单的一部分位于块中而另一部分位于内容中

但是,您希望它可视化,就好像一部分位于正文中,其余部分位于侧边栏中。

好消息是,它与 HTML 表示结构是独立的。这就是您的解决方案所在。

  1. 为您的表单字段提供良好的 ID 和类。您可以使用 hook_form_alter 来更改现有表单,但您可能只想自己为整个表单创建 HTML。主题层允许这样做。
  2. 使用 CSS 按 ID 和位置挑选单个表单字段:将它们绝对到正确的位置。或者按 CLASS 和位置挑选字段类别:将它们相对到正确的位置。
  3. 制作一个简单的识别例程,允许将类添加到主体标签中。 (见下文)。
  4. 添加一些 CSS 来将侧边栏移低,当该类位于 body 标记中时,为要移入的表单字段腾出空间。

    函数 my_themename_preprocess_page() {
      if ($GET['q'] == '路径/到/视图') {
        $vars['spliform'] = "splitform"
      }
    }

First I am going to answer your question, then I will explain why you are asking the wrong question:

If you build the form outside of the formapi, you might have some luck. This will get upgly and will require you to take a lot of extra care about attack-vectors such as mass-assignment.

views_some_view.tpl.php:

<form name="input" action="/link/to/view" method="get">
  Country: <input type="text" name="country" />

my_custom_exposed_view.module:hook_block()
City:

That would make a form, which in most situations will start with <form>, have some input fields, then have a lot of random HTML, then some more input fields and then the closing .

As you may know, a <input type="submit" value="Submit" /> will only post everything of the form tags it is enclosed in. The submit button in the following HTML:

<form name="input_1" action="/link/to/view" method="get">
  Country: <input type="text" name="country" />
</form>
<form name="input_2" action="/link/to/view" method="get">
  City: <input type="text" name="city" />
  <input type="submit" value="Submit" />
</form>

will only send the City. These are not the droids you are looking for.

It will need to be one, big form, but since everything between form and /form is very dynamic, and contains a large quantity of HTML, including potential other forms, this is really not what you want. Moreover: a blocks appearance (shown/not-shown) is controlled completely independent of the content. You will need a lot of sturdy code to ensure the block a) never shows up when the starting form tag is not present, and b) the block will guaranteed to be shown when that opening form tag is present. Else you have not just invalid HTML, but broken HTML that will truly render your page unusable in most cases.

You simply don't want a part of the form in a block and the other part in the content.

However, you want it visualised as if one part is in the body, the rest in a sidebar.

The good news, is that with HTML presentation structure are independant. That is where your solution lies.

  1. Give your form-fields good ids and classes. You could use a hook_form_alter to change existing forms, but you probably simply just want to create the HTML for that entire form yourself. The theme layer allows that.
  2. Use CSS to pick out either single form-fields by ID and position:absolute them into the correct place. Or pick out classes of fields by CLASS and position:relative them into the correct place.
  3. Make a simple identification-routine that allows adding a class to the body-tag. (see below).
  4. Add some CSS to shift the sidebar lower, making space for the form-fields to be moved in, when that class is in the body-tag.

    <body class="<?php print $splitform ?>">

    function my_themename_preprocess_page() {
      if ($GET['q'] == 'path/to/view') {
        $vars['spliform'] = "splitform"
      }
    }
洋洋洒洒 2024-11-25 05:47:46

根据上面的解释,我假设您在块和内容区域中打印相同的表单,并且您在 page.tpl 中隐藏了表单的某些部分,如果这是真的,那么您可以在自定义模块中使用 hook_form_alter() 然后

  1. 存储全局变量中表单元素(存在于块中)的值。
  2. 现在使用该全局变量并设置表单元素(存在于内容区域中,此表单元素对用户不可见)。

如果您以其他方式实现,请提供更多信息。

问候,
金坦。

From the above explanation I am assuming that you are printing same form in block and in content area and you are hiding some part of form in page.tpl , if this is true then you can use hook_form_alter() in your custom module then

  1. Store the value of the form element(present in block) in global variable.
  2. Now use that global variable and set form element(present in content area, this form element is not visible to user).

Provide more information if you implemented other way.

Regards,
Chintan.

青春有你 2024-11-25 05:47:46

这里有一个相关问题:
https://drupal.stackexchange.com/questions/3827/视图过滤器表单暴露过滤器的多个副本
其中描述了如何复制过滤器。然而,这似乎是一个丑陋的黑客。

#6 中提到的这个解决方案似乎更干净一些:
http://drupal.org/node/641838#comment-3247748
还没有测试过,但看起来不错。

它仍然会给您带来一些开销(重复视图),但这可能是使用视图执行此操作的最简单方法。

另一方面,您可以编写一个模块并构建自己的自定义过滤器块,该块会挂接到您的视图中。这是一篇关于此的博客文章:
http:// www.hashbangcode.com/blog/creating-custom-views-filters-exposed-form-element-drupal-6-561.html

There is a related issue here:
https://drupal.stackexchange.com/questions/3827/multiple-copies-of-views-filter-form-exposed-filters
which describes how to duplicate your filters. However it seems like an ugly hack.

A bit cleaner seems this solution mentioned in #6:
http://drupal.org/node/641838#comment-3247748
Haven't tested it out, but it looks good.

It will still give you some overhead (duplicate views) but it might be the easiest way doing this using views.

On the other hand you might write a module and build your own custom filter block which hooks into your view. Here is a blog post about this:
http://www.hashbangcode.com/blog/creating-custom-views-filters-exposed-form-element-drupal-6-561.html

呆头 2024-11-25 05:47:46

如果您使用类似 context 的内容,您可以让公开的过滤器块在同一页面中显示两次。然后,您可以使用 CSS 隐藏您不想在每个表单中显示的字段。

您遇到的根本问题是,要将两个表单放在不同的位置,它们每个都有自己的表单元素 - 当触发提交时,仅发送同一表单元素中的表单字段。您需要将它们移至一种表单中,或者依靠 JavaScript 从两种表单中收集字段并构建帖子。

If you use something like context you could get the exposed filters block to display twice in the same page. You could then use CSS to hide the fields you don't want to do display in each form.

The fundamental problem you're having is that to have the two forms in different places, they'll each have their own form element - when a submit is triggered, only the form fields within the same form element are sent. You need to move them into one form, or rely on JavaScript to gather the fields from both forms and construct the post.

旧人哭 2024-11-25 05:47:46

您可以将块创建为空 div,并让主页中的 javascript 使用辅助过滤器表单以及您需要的其他内容填充它。同样,您可以使用 javascript 将表单值从块表单复制到提交时主表单中的隐藏字段。这为您提供了从一个地方(节点输出)所需的所有控制。唯一需要注意的是,它更多地依赖 javascript 将它们连接在一起。

You could create the block as an empty div and have javascript from the main page populate it with the secondary filter form and whatever else you need in there. Again, you could use javascript to copy the form values from the block form to hidden fields in the main form on submit. That gives you all the control you need from one place (the node output). Only caveat is that it relies a lot more on javascript to join it all together.

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