Am trying to save user information into the database using October CMS Plugin component.
This is how the registration Page looks like registration (register.php)
<h3>Add User</h3>
{% component 'userregistrationform' %}
Here what the Plugin Looks like
<?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')
]
);
}
}
And the plugin's component default.htm looks like this:
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>
And Plugin.php looks like this :
<?php namespace Novaji\Users;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function registerComponents()
{
return [
'Novaji\Users\Components\UsersRegistrationForm' => 'userregistrationform'
];
}
public function registerSettings()
{
}
}
It doesnt throw any error, and it didnt add the record to the database. Please Help, I have tried everything dont seem to know whats wrong, am not even getting any error message, the form just bounces back
So i was able to figure this out, and decided to share with anyone that might the same issue in future.
Solution: I added two October framework scripts just below where i added my custom Javascripts to the
themes/author/layout/default.htm. default.: