laravel - 如何使用 OCtober CMS 插件组件将表单输入保存到数据库
问题描述
我正在尝试使用十月 CMS 插件组件将用户信息保存到数据库中。
这就是注册页面看起来像注册(register.php)
<h3>Add User</h3>
{% component 'userregistrationform' %}
这是插件的样子
<?php namespace Novaji\Users\Components;
use Input;
use Redirect;
use Validator;
use Novaji\Users\Models\User;
use Db;
class UsersRegistrationForm extends \Cms\Classes\ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Users Registration Form',
'description' => 'Accept registration information from users.'
];
}
/**
* This Method Handles User registration
*/
function onSave(){
Db::table('users')->insert(
[
'token' => 'Sample Token',
'email' => Input::get('email'),
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'password' => Input::get('password'),
'user_type' => 'CUSTOMER',
'phone' => post('phone')
]
);
}
}
插件的组件 default.htm 如下所示:
title = "Register"
url = "/customer/register"
layout = "default"
is_hidden = 0
[userregistrationform]
==
<form data-request="onSave" >
<input type="text" name="firstname" placeholder="Firstname"/> <br>
<input type="text" name="lastname" placeholder="Lastname" /> <br>
<input type="text" name="email" placeholder="Email"/><br>
<input type="text" name="phone" placeholder="Phone number"><br>
<button type="submit">Register</button>
</form>
Plugin.php 看起来像这样:
<?php namespace Novaji\Users;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function registerComponents()
{
return [
'Novaji\Users\Components\UsersRegistrationForm' => 'userregistrationform'
];
}
public function registerSettings()
{
}
}
它没有抛出任何错误,也没有将记录添加到数据库中。请帮助,我已经尝试了一切似乎不知道出了什么问题,甚至没有收到任何错误消息,表单只是弹回
解决方案
因此,我能够弄清楚这一点,并决定与将来可能遇到相同问题的任何人分享。
解决方案:我在将自定义 Javascript 添加到themes/author/layout/default.htm
. 默认。:
...
...
...
//html scripts before
<script src="{{ 'assets/javascript/app.js'|theme }}"></script>
{% framework extras %}
{% scripts %}
</body>
</html>
推荐阅读
- reactjs - React 中的渲染顺序
- database - 错误的密码/电子邮件错误身份验证活动 - 使用 SQLite
- http - windows如何解除对端口的阻塞
- php - 用php或sql过滤数据?
- android - 单击软键盘上的“搜索”按钮时,搜索视图消失
- python-3.x - python - 如果在使用两个文件搜索时字典中缺少值字段,如何跳过或放置None
- php - 按键值对数组进行排序,然后得到数组中的 5 个最高和最低值
- c# - ValidateAntiForgeryToken Filter is not working
- java - Java功能接口的单例作为枚举
- angular - Angular:在内容投影时获取对父组件的引用