我在插件目录中创建了一个组件,在default.htm中,我将表单html放入了我的组件中。但是当我提交表单时,我得到“找不到AjaxHandler Component: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[]">
{% 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[]">
{% 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提交表单
答案 0 :(得分:0)
您需要在部分代码中添加
部分代码:
[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
如有疑问,请发表评论。
答案 1 :(得分:0)
已解决。我忘记从后端添加成分在内容布局
答案 2 :(得分:0)
{%框架额外费用%}
是必需的,如果您要使用部分,则将其放在部分中。
如果有人仍然有问题,这是为了将来。