Drupal 中的较长表单字段
我有一个非常愚蠢的问题,已经花费了我很多时间。
我创建了一个内容模板,其中包含 URL。当我查看它的 HTML 代码时,我在表单标记中看到一个大的“maxlength=256”。我想扩展此字段的长度,因为我的客户希望输入很长的链接(超过 500 个字符)。知道我该如何改变它吗?当我对代码进行一般搜索时,我发现 256 出现了很多次,但长度也可能在数据库中的某个地方。当然,我已经将数据库字段设置为更长的 varchar(1024 对我来说听起来很诗意),所以这是我不必担心的事情。
我认为这很愚蠢,但正如我们所知,客户总是对的。
我正在使用 Drupal 6.14。
I have a really silly problem that has cost me a load of time already.
I have created a content template with a URL in there. When I look at the HTML code for it, I see a big fat "maxlength=256" in the form tag. I'd like to expand the length of this field, because my customer wishes to enter really long links (over 500 characters). Any idea how I can change it? When I do a generic search through the code I see so many occurences of 256, but the length might just as well be in the database somewhere. I have of course made the database field a longer varchar (1024 sounded poetic to me), so that's something I don't have to worry about.
I think it's silly, but the customer's always right, as we know.
I am using Drupal 6.14.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想在
templete.php 或自定义模块中使用 hook_form_alter()。它看起来像这样:
只需将 MODULE 替换为
主题的名称(如果在 template.php 中)或将其替换为您使用的自定义模块的名称。要查找表单的 id,请使用 firebug 检查该元素。 url 字段的 id 也是如此。
如果您需要更多详细信息,请告诉我。
编辑:正如所指出的,您似乎无法从主题级别调用挂钩。
解决此问题的最佳方法是为您的网站创建一个小型自定义模块。您可以将其称为 SITENAME_customizations 之类的名称。
您所需要的只是一个名为 MODULENAME.info 的简单 .info 文件,该文件如下所示:
您还需要一个 MODULENAME.module 文件,您将在其中包含
hook_form_alter
调用。附言。确保您没有关闭 .module 文件中的 php 标记 (
?>
)。You want to use a hook_form_alter() in
your templete.php ora custom module.It will look something like this:
Just replace MODULE with the name of
your theme (if in template.php) or replace it with the name ofthe custom module your using.To find the id of the form, inspect the element with firebug. Same goes for the id of the url field.
Let me know if you need more detail.
EDIT: As pointed out, it looks like you can't call hooks from the theme level.
The best way to go about this is to create a small custom module for you site. You can call it something like SITENAME_customizations.
All you need is a simple .info file named MODULENAME.info which will look something like this:
You will also need a MODULENAME.module file, which is where you will include your
hook_form_alter
call.PS. Make sure that you don't close your php tag (
?>
) in your .module file.雅呼呼!感谢有用的 Drupal 页面,我修复了它:
http://drupal.org/node/300705
我发现我可以在表单完成后对其进行编辑已完全生成。 Erik 提出的解决方案很好,但似乎不适用于 CCK 领域。就我而言,如果不是需要首先发生这一生成步骤,埃里克的解决方案可能会起作用。
我的新代码如下:
现在,我也发现它很丑陋,特别是因为这里可能还有其他表单元素(只是从 0 开始递增),但它适用于第一个元素!耶皮!
Yahoooooo! I fixed it, thanks to the helpful Drupal pages:
http://drupal.org/node/300705
I figured out I could edit the form after it has been generated completely. The solution presented by Erik is good, but doesn't appear to work for CCK fields. In my case Erik's solution could have worked if it wasn't for this generation step that needs to happen first.
My new code is as follows:
Now, I too see that it's ugly, especially because there might be other form elements here (just increment from 0), but it works for the first element! Yippeee!