【问题标题】:How to Save form input to database using OCtober CMS Plugin Component如何使用 OCtober CMS 插件组件将表单输入保存到数据库
【发布时间】:2019-12-04 15:04:28
【问题描述】:

我正在尝试使用十月 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()
    {
    }
}

它没有抛出任何错误,也没有将记录添加到数据库中。 请帮助,我已经尝试了一切似乎不知道出了什么问题,甚至没有收到任何错误消息,表单只是弹回

【问题讨论】:

    标签: laravel eloquent octobercms octobercms-plugins october-form-controller


    【解决方案1】:

    所以我能够弄清楚这一点,并决定与将来可能遇到相同问题的任何人分享。
    解决方案: 我添加了两个 10 月框架脚本,就在我将自定义 Javascripts 添加到 themes/author/layout/default.htm 的位置下方。默认值:

    ...
    ...
    ...
    //html scripts before 
    <script src="{{ 'assets/javascript/app.js'|theme }}"></script>
    {% framework extras %}
    {% scripts %}
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 2019-07-16
      • 1970-01-01
      • 2021-01-29
      相关资源
      最近更新 更多