【问题标题】:OctoberCMS Form not submiting (AJAX handler not found)OctoberCMS 表单未提交(未找到 AJAX 处理程序)
【发布时间】:2019-06-21 08:40:43
【问题描述】:

我在我的插件目录中创建了一个组件,在 default.htm 中我将我的表单 html 并包含在我的部分中。但是当我提交表单时,我得到“AjaxHandler 组件:onSend 未找到”

default.htm

<div class="filter-holder">
    <div class="container">
        <div class="row">
 <form name="contact-form" data-request="{{ __SELF__ }}::onSend" data-request-success="alert('Message Sent')">

                <div class="col-md-5">
                    <input type="text" name="agent" class="form-control">
                </div>
                <div class="col-md-2">

                    <select class="form-control" id="services" name="services[]">&nbsp;
                        {% for client in records %}
                            <option value="{{ client.service }}">{{ client.service }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-2">
                    <select class="form-control" id="search" name="area[]">&nbsp;
                        {% for client in records %}
                            <option value="{{ client.area }}">{{ client.area }} Miles</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-3">
                    <input type="submit" value="Agents" class="red-btn btn btn-default">
                    <a class="location-view" href="#">location</a></div>
            </form>

ComponentClass.php

class MarkerData extends ComponentBase {

    public function componentDetails() {
        return [
            'name' => 'Marker Data',
            'description' => 'List of marker data'
        ];
    }


    public function onSend()
    {
       $data = post();
       print_r($data);die;
    }}

并且在我的部分文件中,我包含了组件

{% 组件 "MarkerData" %}

Partial Code:

description = "A quick way to reference testimonials in the theme."

[viewBag]
snippetCode = "location-form"
snippetName = "Locations"
snippetProperties[category][title] = "Select Category"
snippetProperties[category][type] = "dropdown"
snippetProperties[category][default] = "customer"
snippetProperties[category][options][customer] = "Customer"
snippetProperties[category][options][agent] = "Agent"

[builderList]
modelClass = "Tech\Locations\Models\Location"
scope = "-"
scopeValue = "{{ :scope }}"
displayColumn = "name"
noRecordsMessage = "No records found"
detailsPage = "-"
detailsUrlParameter = "id"
pageNumber = "{{ :page }}"

[MarkerData]
==
{% set records = builderList.records %}
{% set displayColumn = builderList.displayColumn %}
{% set noRecordsMessage = builderList.noRecordsMessage %}
{% set detailsPage = builderList.detailsPage %}
{% set detailsKeyColumn = builderList.detailsKeyColumn %}
{% set detailsUrlParameter = builderList.detailsUrlParameter %}
{% component "MarkerData" %}

我希望我的表单能够访问组件中定义的方法。在OctoberCMS中是否有任何其他方式通过ajax提交表单

【问题讨论】:

  • 你的表单代码不完整,你可以把整个部分代码。
  • @HardikSatasiya 已添加。
  • 你的 default.htm 代码被破坏了,我猜是从上面说的 :)
  • 是的,我也编辑它。它只有html。 :)
  • 嗯,你确定你在部分中包含{% component "MarkerData" %},因为我看到你包含{% component "LocationData" %},但不是markerdata

标签: ajax laravel octobercms october-form-controller


【解决方案1】:

在你的部分代码中你需要添加

部分代码:

[viewBag]
snippetCode = "location-form"
snippetName = "Locations"
snippetProperties[category][title] = "Select Category"
snippetProperties[category][type] = "dropdown"
snippetProperties[category][default] = "customer"
snippetProperties[category][options][customer] = "Customer"
snippetProperties[category][options][agent] = "Agent"

[builderList]
modelClass = "Tech\Locations\Models\Location"
scope = "-"
scopeValue = "{{ :scope }}"
displayColumn = "name"
noRecordsMessage = "No records found"
detailsPage = "-"
detailsUrlParameter = "id"
pageNumber = "{{ :page }}"

[LocationData] <======= I guess this is not needed
[MarkerData] <========= This ONE you need add
==
{% set records = builderList.records %}
{% set displayColumn = builderList.displayColumn %}
{% set noRecordsMessage = builderList.noRecordsMessage %}
{% set detailsPage = builderList.detailsPage %}
{% set detailsKeyColumn = builderList.detailsKeyColumn %}
{% set detailsUrlParameter = builderList.detailsUrlParameter %}
{% component "MarkerData" %}

之后,它会将MarkerData 添加到该页面,以便OctoberCMS 可以找到that component and its Ajax-handler

如有疑问请评论。

【讨论】:

  • 提交“Ajaxhandler onSend not found”时仍然报错。我的组件文件中有 onSend 方法。
【解决方案2】:

已解决。我忘记在后端的内容布局中添加组件

【讨论】:

  • 所以这意味着你现在包含了两次组件。一个在布局中,一个在部分中???
  • @Zakirhussain 是的
  • @rameez.hashmi 我认为在我的回答中我也建议添加该组件。
  • @HardikSatasiya 我以为你说要向部分添加组件
  • @rameez.hashmi 如果您没有在其他任何地方为此部分使用组件,那么明智的做法是将其添加到partial 中作为layout included in other pages as well。如果您需要在添加此布局的页面中使用该组件,那么明智的做法是将其添加到layout。 - 所以这取决于你在哪里添加它。根据您的回答,它适合部分添加。 - 因为我没有关于你的结构的更多信息所以。但缺少的项目是添加它:)
【解决方案3】:

{% 框架附加功能 %}

如果您使用部分,则需要将其放入部分中。

如果有人仍然有问题,这是为了将来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多