简体   繁体   English

以drupal形式使用预处理

[英]Using preprocess in drupal form

i have prepared a drupal registration form with basic fields like name,email,etc. 我已经准备了一个drupal注册表格,其中包含姓名,电子邮件等基本字段。 Then i created a display function where data is selected from database and displayed. 然后我创建了一个显示功能,可以从数据库中选择数据并进行显示。 Now my instructor asked me to somehow include preprocessor in my program.How do i do it? 现在我的老师要求我以某种方式在程序中包含预处理器。我该怎么做?

Your question is not very clear, like what version of drupal are you using and how did you create webform, with back-end interface or from code and I guess you are going to get some down votes for your question, but I'll try to help anyway. 您的问题不是很清楚,例如您使用的是什么版本的drupal,以及如何使用后端界面或代码来创建Webform,我想您会对此问题有所反对,但我会尽力无论如何都可以提供帮助。

So, Drupal uses so called "hooks" system. 因此,Drupal使用了所谓的“挂钩”系统。 You have some process, like web form creations and it's done from several steps. 您有一些过程,例如Web表单创建,它是通过几个步骤完成的。 At some points (ie between those steps) you can interrupt the process, let you own code execute and then let process continue with normal flow. 在某些时候(例如,在这些步骤之间),您可以中断进程,让您自己的代码执行,然后让进程按正常流程继续进行。

Way to do that is by creating your own hooks functions. 做到这一点的方法是创建自己的钩子函数。 You have to make your module (some can work even from theme's template.php file), then create hook function inside module file, give it specific name, to meet some standards, clear the cash and Drupal will take care to call your hook function when appropriate event happens. 您必须制作模块(某些模块甚至可以从主题的template.php文件运行),然后在模块文件内创建挂钩函数,为其指定特定名称,以满足某些标准,清除现金,而Drupal会小心地调用您的挂钩函数当适当的事件发生时。

The hook you'll have to create most likely is: 您最有可能创建的钩子是:

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7.x https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7.x

So if your module is called ie"saikat" (it's machine name) you'll have to create function called: 因此,如果您的模块名为“ saikat”(它是机器名称),则必须创建一个名为:

    saikat_form_alter($form, $form_state, $form_id)
    {
      // Do your magic here
    }

This hook will be called for every form you have on your website so check on $form_id value to match your form id to alter only your form and no others as well. 您在网站上拥有的每个表单都会调用此钩子,因此请检查$ form_id值以匹配您的表单ID,以仅更改您的表单,而不更改其他表单。 And don't forget to clear the cache. 并且不要忘记清除缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM