Drupal 测验模块 - 参加测验后通过电子邮件发送结果
我有一个 Drupal 网站,它使用测验模块来管理访问者的测试。这些测试需要可供匿名用户使用。我的问题是我需要能够要求考生输入姓名和电子邮件,以便将结果发送给他们。我只是不知道该怎么做。我认为自己是 Drupal 和 PHP 的初学者。 任何帮助将不胜感激。
I have a Drupal website that uses the Quiz module to administer tests to visitors. These tests need to be available to anonymous users. My problem is that I need to be able to ask the test taker to enter name and e-mail so the results can be sent to them. I just don't know how to go about doing this. I consider myself a beginner in Drupal and PHP.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-首先,创建一个自定义模块。
-其次,您需要添加电子邮件地址和姓名字段。您可以通过 hook_form_alter 在您的自定义模块中,或者通过启用和使用测验模块中包含的简答模块/字段,然后根据您的需要自定义字段的样式(因为它看起来像一个问题)。就我个人而言,我建议使用 hook_form_alter 添加它们。另外,我建议您了解 Hooks在 Drupal 中,它会让您的生活更轻松。
- 您必须验证并检索这两个字段的值。您还可以为此使用相同的 form_alter 挂钩。 添加验证和提交函数到测验表单的验证和提交堆栈(
$form['#validate'][] = 'your_validate_function';
和$form['#submit'][] = 'your_submit_function';
)。您可以使用 Drupal 的函数 valid_email_address,当然,您可以验证其他字段并调用 Drupal 的 form_set_error 通知用户任何输入错误。- 要在提交测验后发送电子邮件,请在提交函数中调用 Drupal 的 drupal_mail,该函数基本上采用发送电子邮件所需的所有参数。您必须在自定义模块中创建一个 hook_mail。在此处查看如何执行此操作的示例。您可以从本地数组 $form_state['values'] 检索表单值(姓名和电子邮件地址),将它们作为 $params 传递给 drupal_mail 函数,并将它们添加到 hook_mail 函数中的电子邮件正文中。就是这样:D
- 或者,您可以通过创建操作并分配要在用户完成此测验后执行的操作来发送电子邮件。测验模块对此提供支持。以下是如何编写操作的示例。
-First of all, create a custom module.
-Secondly, you need to add the email address and name fields. You can do this by either adding the two fields via hook_form_alter in your custom module or by enabling and using the Short Answer module/field that's included in your Quiz module and then customising the style of the field according to your needs (because it'll look like a question). Personally, I would recommend adding them using hook_form_alter. Plus, I suggest you learn about Hooks in Drupal, it will make your life easier.
-You have to validate and retrieve the values for the two fields. You can also use the same form_alter hook for this. Add a validation and a submission function to the validate and the submit stack of your Quiz form (
$form['#validate'][] = 'your_validate_function';
and$form['#submit'][] = 'your_submit_function';
). You can validate your email by using Drupal's function valid_email_address and, of course, you can validate other fields and calling Drupal's form_set_error to notify users of any input mistakes.-To send your email after the Quiz is submitted, call Drupal's drupal_mail, in your submit function, which basically takes all the parameters needed to send an email. You'll have to create a hook_mail in your custom module. Check out an example of how to do this here. You can retrieve your form values (name and email address) from the local array $form_state['values'], pass them as $params to your drupal_mail function and add them to the body of your email in your hook_mail function. And that's it :D
-Alternatively, you can send an email by creating an action and assigning an action to be performed after a user has completed this Quiz. The Quiz module has support for that. Here's an example of how to write an action.
您还可以使用
hook_quiz_finished
而不是表单提交回调。测验模块使用它来执行操作,例如在测验结束时通过电子邮件发送结果。
You may also use
hook_quiz_finished
instead of form submit callback.Quiz module uses it to perform actions like sending results over email at the end of a quiz.
如果您在此处结束并且正在使用 Drupal 7,请转至规则 http://www. yourwebsite.com/admin/config/workflow/rules,并设置测验模块已在设置下激活的规则,该规则称为“在测验结束时发送测验结果”。我在测验配置本身的任何地方都找不到执行此操作的功能。已测试及其工作原理。确保启用规则模块 UI 以允许您进行编辑。
If you ended here and you are using Drupal 7, go to Rules http://www.yourwebsite.com/admin/config/workflow/rules, and set the rule that the Quiz module has made available already to active under the settings, the rule is called "Send quiz results at the end of a quiz". I couldn't find the ability to do this anywhere within the Quiz config itself. Tested and its working. Be sure that the Rules Module UI is enabled to allow you to make the edits.