【问题标题】:Validation and Email not working on OctoberCMS验证和电子邮件在 OctoberCMS 上不起作用
【发布时间】:2019-07-01 11:41:16
【问题描述】:

我的问题:

我在 Azure 上运行 OctoberCMS,并尝试在 10 月使用“Magic Forms”插件。我正在使用通用表单并成功提交并显示在后端。

我的问题是我想在提交表单时发送电子邮件通知,我设置了 stmp 并且测试消息正确发送,但提交时没有任何反应。

我的另一个问题是验证或 JsOnSuccess 都没有触发。

我尝试过的一些事情:

  • 我已经为名称字段设置了我自己的规则和我自己的规则消息,但没有任何改变。

  • 我已尝试对所有电子邮件详细信息进行硬编码,但仍然没有发送电子邮件,即使测试消息有效。

我的表单代码:

[viewBag]
snippetCode = "formAccountingServices"
snippetName = "Form Accounting Services"

[emptyForm formAccountingServices]
group = "Accounting-Services"
rules[name] = "required"
rules[email] = "required|email"
rules[phone] = "required"
rules[service] = "required"
rules[message] = "required"
messages_success = "Your form was successfully submitted"
messages_errors = "There were errors with your submission"
mail_enabled = 1
mail_subject = "Test Subject"
mail_recipients[] = "myemail@gmail.ie"
mail_replyto = "emailFromForm@gmail.com"
reset_form = 1
redirect = "https://myHomeUrl.com"
inline_errors = "display"
js_on_success = "window.location.href = 'http://stackoverflow.com;'"
sanitize_data = "disabled"
anonymize_ip = "disabled"
recaptcha_theme = "light"
recaptcha_type = "image"
recaptcha_size = "normal"
==
<form data-request="{{ formAccountingServices}}::onFormSubmit">

{{ form_token() }}

<div id="{{ formAccountingServices }}_forms_flash"></div>

<div class="form-group">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" class="form-control">
</div>

<div class="form-group">
    <label for="email">Email:</label>
    <input type="text" id="email" name="email" class="form-control">
</div>

<div class="form-group">
    <label for="phone">Phone:</label>
    <input type="text" id="phone" name="phone" class="form-control">
</div>

<div class="form-group">
    <label for="service">Service of interest</label>
    <select name="service" id="service" class="form-control">
      <option value="Accounting Services">Accounting Services</option>
      <option value="Legal Services">Legal Services</option>
    </select>
  </div>

<div class="form-group">
    <label for="message">Message</label>
    <textarea id="message" name="message" rows="8" cols="80"></textarea>
</div>

<button id="simpleContactSubmitButton" type="submit" class="btn btn-default">Submit</button>

</form>

预期结果:

  • 我希望所有字段都是必需的,如果某些字段为空则不允许提交。
  • 成功提交表单后,它将向设置的电子邮件地址发送一封通知电子邮件并重定向到主页。
  • 提交失败时显示错误消息。

实际结果:

  • 无论字段是否为空,每次都会提交表单。
  • 不发送通知电子邮件。
  • 页面未重定向。

【问题讨论】:

  • 您能否向我们展示您用于验证的代码以及用于通知的代码,如果您向我们展示该代码,我们可以提供帮助
  • 我正在使用 Magic Forms 插件,因此我不必自己编写验证和通知电子邮件,因为我正在努力节省开发时间。我设法通过将代码从模式移动到页面来解决这个问题,并且它刚刚工作。

标签: laravel octobercms octobercms-plugins


【解决方案1】:

您是否使用自定义主题? Magic Form 显式使用 ajax。确保在 {% framework extras %} 之前加载了 jquery,我不记得它是否需要 {% scripts %}。

一个更好的寻求帮助的地方也可能是插件https://github.com/skydiver/october-plugin-forms的github。

【讨论】:

  • 这不在文档中,您应该添加 {% framework extras %} .... 不过还是谢谢
【解决方案2】:

我找到了解决方案!

只需将 Magic Forms 插件生成的设置如下:

[viewBag]

[genericForm contactForm]
rules[name] = "required"
rules[email] = "required|email"
rules[message] = "required"
rules[tel] = "required".... etc
==

像这样进入部分注入的页面 {% partial 'sections/contact' %} 然后,您可以将组件“contactForm”(在我的情况下,当然)注入到部分“sections/contact”中,例如 {% component "contactForm" %}

记得在 jQuery 脚本之前在布局中包含 {% framework extras %} 以启用 ajax 处理程序。

就是这样!

【讨论】:

  • 关于脚本:应该是相反的。 jQuery FIRST,然后是“框架附加功能”。否则,您将得到“未加载 jQuery 库。无法初始化 OctoberCMS 框架”。在控制台中。
猜你喜欢
  • 1970-01-01
  • 2017-05-27
  • 2012-08-19
  • 2019-01-01
  • 2015-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多