Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for October CMS v3 #269

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Use issues to report errors / bugs only.

Do you have questions?
* Read the docs: https://skydiver.github.io/october-plugin-forms/docs/introduction/
* Start a discussion: https://github.com/skydiver/october-plugin-forms/discussions
* Start a discussion: https://github.com/blakej115/magic-forms/discussions

-->
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/skydiver/october-plugin-forms/discussions
url: https://github.com/blakej115/magic-forms/discussions
about: Ask questions and discuss with other community members
68 changes: 34 additions & 34 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
<?php

namespace Martin\Forms;
namespace BlakeJones\MagicForms;

use Backend, Lang, Validator;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use Martin\Forms\Classes\BackendHelpers;
use Martin\Forms\Classes\GDPR;
use Martin\Forms\Classes\ReCaptchaValidator;
use Martin\Forms\Classes\UnreadRecords;
use Martin\Forms\Models\Settings;
use BlakeJones\MagicForms\Classes\BackendHelpers;
use BlakeJones\MagicForms\Classes\GDPR;
use BlakeJones\MagicForms\Classes\ReCaptchaValidator;
use BlakeJones\MagicForms\Classes\UnreadRecords;
use BlakeJones\MagicForms\Models\Settings;

class Plugin extends PluginBase {

public function pluginDetails() {
return [
'name' => 'martin.forms::lang.plugin.name',
'description' => 'martin.forms::lang.plugin.description',
'author' => 'Martin M.',
'name' => 'blakejones.magicforms::lang.plugin.name',
'description' => 'blakejones.magicforms::lang.plugin.description',
'author' => 'Martin M. (Forked by Blake Jones)',
'icon' => 'icon-bolt',
'homepage' => 'https://github.com/skydiver/'
'homepage' => 'https://github.com/blakej115/magic-forms'
];
}

public function registerNavigation() {
if(Settings::get('global_hide_button', false)) { return; }
return [
'forms' => [
'label' => 'martin.forms::lang.menu.label',
'label' => 'blakejones.magicforms::lang.menu.label',
'icon' => 'icon-bolt',
'iconSvg' => 'plugins/martin/forms/assets/imgs/icon.svg',
'url' => BackendHelpers::getBackendURL(['martin.forms.access_records' => 'martin/forms/records', 'martin.forms.access_exports' => 'martin/forms/exports'], 'martin.forms.access_records'),
'permissions' => ['martin.forms.*'],
'iconSvg' => 'plugins/blakejones/magicforms/assets/imgs/icon.svg',
'url' => BackendHelpers::getBackendURL(['blakejones.magicforms.access_records' => 'blakejones/magicforms/records', 'blakejones.magicforms.access_exports' => 'blakejones/magicforms/exports'], 'blakejones.magicforms.access_records'),
'permissions' => ['blakejones.magicforms.*'],
'sideMenu' => [
'records' => [
'label' => 'martin.forms::lang.menu.records.label',
'label' => 'blakejones.magicforms::lang.menu.records.label',
'icon' => 'icon-database',
'url' => Backend::url('martin/forms/records'),
'permissions' => ['martin.forms.access_records'],
'url' => Backend::url('blakejones/magicforms/records'),
'permissions' => ['blakejones.magicforms.access_records'],
'counter' => UnreadRecords::getTotal(),
'counterLabel' => 'Un-Read Messages'
],
'exports' => [
'label' => 'martin.forms::lang.menu.exports.label',
'label' => 'blakejones.magicforms::lang.menu.exports.label',
'icon' => 'icon-download',
'url' => Backend::url('martin/forms/exports'),
'permissions' => ['martin.forms.access_exports']
'url' => Backend::url('blakejones/magicforms/exports'),
'permissions' => ['blakejones.magicforms.access_exports']
],
]
]
Expand All @@ -55,44 +55,44 @@ public function registerNavigation() {
public function registerSettings() {
return [
'config' => [
'label' => 'martin.forms::lang.menu.label',
'description' => 'martin.forms::lang.menu.settings',
'label' => 'blakejones.magicforms::lang.menu.label',
'description' => 'blakejones.magicforms::lang.menu.settings',
'category' => SettingsManager::CATEGORY_CMS,
'icon' => 'icon-bolt',
'class' => 'Martin\Forms\Models\Settings',
'permissions' => ['martin.forms.access_settings'],
'class' => 'BlakeJones\MagicForms\Models\Settings',
'permissions' => ['blakejones.magicforms.access_settings'],
'order' => 500
]
];
}

public function registerPermissions() {
return [
'martin.forms.access_settings' => ['tab' => 'martin.forms::lang.permissions.tab', 'label' => 'martin.forms::lang.permissions.access_settings'],
'martin.forms.access_records' => ['tab' => 'martin.forms::lang.permissions.tab', 'label' => 'martin.forms::lang.permissions.access_records'],
'martin.forms.access_exports' => ['tab' => 'martin.forms::lang.permissions.tab', 'label' => 'martin.forms::lang.permissions.access_exports'],
'martin.forms.gdpr_cleanup' => ['tab' => 'martin.forms::lang.permissions.tab', 'label' => 'martin.forms::lang.permissions.gdpr_cleanup'],
'blakejones.magicforms.access_settings' => ['tab' => 'blakejones.magicforms::lang.permissions.tab', 'label' => 'blakejones.magicforms::lang.permissions.access_settings'],
'blakejones.magicforms.access_records' => ['tab' => 'blakejones.magicforms::lang.permissions.tab', 'label' => 'blakejones.magicforms::lang.permissions.access_records'],
'blakejones.magicforms.access_exports' => ['tab' => 'blakejones.magicforms::lang.permissions.tab', 'label' => 'blakejones.magicforms::lang.permissions.access_exports'],
'blakejones.magicforms.gdpr_cleanup' => ['tab' => 'blakejones.magicforms::lang.permissions.tab', 'label' => 'blakejones.magicforms::lang.permissions.gdpr_cleanup'],
];
}

public function registerComponents() {
return [
'Martin\Forms\Components\GenericForm' => 'genericForm',
'Martin\Forms\Components\UploadForm' => 'uploadForm',
'Martin\Forms\Components\EmptyForm' => 'emptyForm',
'BlakeJones\MagicForms\Components\GenericForm' => 'genericForm',
'BlakeJones\MagicForms\Components\UploadForm' => 'uploadForm',
'BlakeJones\MagicForms\Components\EmptyForm' => 'emptyForm',
];
}

public function registerMailTemplates() {
return [
'martin.forms::mail.notification' => Lang::get('martin.forms::lang.mails.form_notification.description'),
'martin.forms::mail.autoresponse' => Lang::get('martin.forms::lang.mails.form_autoresponse.description'),
'blakejones.magicforms::mail.notification',
'blakejones.magicforms::mail.autoresponse',
];
}

public function register() {
$this->app->resolving('validator', function($validator) {
Validator::extend('recaptcha', 'Martin\Forms\Classes\ReCaptchaValidator@validateReCaptcha');
Validator::extend('recaptcha', 'BlakeJones\MagicForms\Classes\ReCaptchaValidator@validateReCaptcha');
});
}

Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Magic Forms for OctoberCMS
# Magic Forms for October CMS v3
Create easy (and almost magic) AJAX forms.


# Support for October CMS v3 (Forked)
The original version of this plugin was [abandoned](https://github.com/skydiver/october-plugin-forms/discussions/267). This is an actively maintained fork of the [original plugin](https://octobercms.com/plugin/martin-forms) that supports October CMS v3.

## Why Magic Forms?
Almost everyday we do forms for our clients, personal projects, etc
Expand All @@ -10,8 +11,6 @@ Sometimes we need to add or remove fields, change validations, store data and at

So, the objective was to find a way to just put the HTML elements on the page, skip the repetitive task of coding and (with some kind of magic) store this data on a database or send by mail.



## Features
* Create any type of form: contact, feedback, registration, uploads, etc
* Write only HTML
Expand All @@ -29,8 +28,8 @@ So, the objective was to find a way to just put the HTML elements on the page, s
* Inline errors with fields (read documentation for more info)
* AJAX file uploads (BETA, available since v1.3.0)

## Documentation

New documentation coming soon. For now, you may reference the old documentation:

## Documentation
Checkout our docs at:
> https://skydiver.github.io/october-plugin-forms/
> https://skydiver.github.io/october-plugin-forms/docs/introduction/
6 changes: 3 additions & 3 deletions classes/BackendHelpers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Backend, BackendAuth;

Expand Down Expand Up @@ -30,7 +30,7 @@ public static function getBackendURL(array $urls, string $default) :string {
* @return boolean
*/
public static function isTranslatePlugin() :bool {
return class_exists('\RainLab\Translate\Classes\Translator') && class_exists('\RainLab\Translate\Models\Message');
return class_exists('\RainLab\Translate\Classes\Translator') && class_exists('\RainLab\Translate\Models\Message') && class_exists('\RainLab\Translate\Classes\Locale');
}

/**
Expand Down Expand Up @@ -84,4 +84,4 @@ public static function replaceToken(string $pattern, string $replacement = null,

}

?>
?>
10 changes: 5 additions & 5 deletions classes/GDPR.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Flash;
use Request;
use Martin\Forms\Models\Record;
use Martin\Forms\Models\Settings;
use BlakeJones\MagicForms\Models\Record;
use BlakeJones\MagicForms\Models\Settings;
use Carbon\Carbon;
use October\Rain\Exception\ApplicationException;
use October\Rain\Exception\ValidationException;
Expand All @@ -18,7 +18,7 @@ public static function cleanRecords() {
$gdpr_days = Settings::get('gdpr_days' , false);

if (!$gdpr_enable) {
Flash::error(e(trans('martin.forms::lang.classes.GDPR.alert_gdpr_disabled')));
Flash::error(e(trans('blakejones.magicforms::lang.classes.GDPR.alert_gdpr_disabled')));
return;
}

Expand All @@ -28,7 +28,7 @@ public static function cleanRecords() {
return $rows;
}

Flash::error(e(trans('martin.forms::lang.classes.GDPR.alert_invalid_gdpr')));
Flash::error(e(trans('blakejones.magicforms::lang.classes.GDPR.alert_invalid_gdpr')));

}

Expand Down
34 changes: 13 additions & 21 deletions classes/MagicForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Lang;
use Config;
Expand All @@ -10,18 +10,18 @@
use Validator;
use AjaxException;
use Cms\Classes\ComponentBase;
use Martin\Forms\Models\Record;
use Martin\Forms\Models\Settings;
use Martin\Forms\Classes\SendMail;
use BlakeJones\MagicForms\Models\Record;
use BlakeJones\MagicForms\Models\Settings;
use BlakeJones\MagicForms\Classes\SendMail;
use Illuminate\Support\Facades\Event;
use Martin\Forms\Classes\BackendHelpers;
use BlakeJones\MagicForms\Classes\BackendHelpers;
use October\Rain\Exception\ValidationException;

abstract class MagicForm extends ComponentBase
{

use \Martin\Forms\Classes\ReCaptcha;
use \Martin\Forms\Classes\SharedProperties;
use \BlakeJones\MagicForms\Classes\ReCaptcha;
use \BlakeJones\MagicForms\Classes\SharedProperties;

public function onRun() {

Expand All @@ -33,7 +33,7 @@ public function onRun() {
}

if ($this->isReCaptchaMisconfigured()) {
$this->page['recaptcha_warn'] = Lang::get('martin.forms::lang.components.shared.recaptcha_warn');
$this->page['recaptcha_warn'] = Lang::get('blakejones.magicforms::lang.components.shared.recaptcha_warn');
}

if ($this->property('inline_errors') == 'display') {
Expand All @@ -59,18 +59,10 @@ public function onFormSubmit() {
throw new AjaxException(['#' . $this->alias . '_forms_flash' => $this->renderPartial($flash_partial, [
'status' => 'error',
'type' => 'danger',
'content' => Lang::get('martin.forms::lang.components.shared.csrf_error'),
'content' => Lang::get('blakejones.magicforms::lang.components.shared.csrf_error'),
])]);
}

// LOAD TRANSLATOR PLUGIN
if (BackendHelpers::isTranslatePlugin()) {
$translator = \RainLab\Translate\Classes\Translator::instance();
$translator->loadLocaleFromSession();
$locale = $translator->getLocale();
\RainLab\Translate\Models\Message::setContext($locale);
}

// FILTER ALLOWED FIELDS
$allow = $this->property('allowed_fields');
if (is_array($allow) && !empty($allow)) {
Expand Down Expand Up @@ -150,7 +142,7 @@ public function onFormSubmit() {

// PREPARE RECAPTCHA VALIDATION
$rules = ['g-recaptcha-response' => 'recaptcha'];
$err_msg = ['g-recaptcha-response.recaptcha' => Lang::get('martin.forms::lang.validation.recaptcha_error')];
$err_msg = ['g-recaptcha-response.recaptcha' => Lang::get('blakejones.magicforms::lang.validation.recaptcha_error')];

// DO SECOND VALIDATION
$validator = Validator::make($post, $rules, $err_msg);
Expand All @@ -165,7 +157,7 @@ public function onFormSubmit() {
throw new AjaxException($this->_exceptionResponse($validator, [
'status' => 'error',
'type' => 'danger',
'content' => Lang::get('martin.forms::lang.validation.recaptcha_error'),
'content' => Lang::get('blakejones.magicforms::lang.validation.recaptcha_error'),
'errors' => json_encode($validator->messages()->messages()),
'jscript' => $this->property('js_on_error'),
]));
Expand All @@ -179,7 +171,7 @@ public function onFormSubmit() {
unset($post['_token'], $post['g-recaptcha-response'], $post['_session_key'], $post['_uploader']);

// FIRE BEFORE SAVE EVENT
Event::fire('martin.forms.beforeSaveRecord', [&$post, $this]);
Event::fire('blakejones.magicforms.beforeSaveRecord', [&$post, $this]);

if (count($custom_attributes)) {
$post = collect($post)->mapWithKeys(function ($val, $key) use ($custom_attributes) {
Expand Down Expand Up @@ -211,7 +203,7 @@ public function onFormSubmit() {
}

// FIRE AFTER SAVE EVENT
Event::fire('martin.forms.afterSaveRecord', [&$post, $this, $record]);
Event::fire('blakejones.magicforms.afterSaveRecord', [&$post, $this, $record]);

// CHECK FOR REDIRECT
if ($this->property('redirect')) {
Expand Down
6 changes: 3 additions & 3 deletions classes/ReCaptcha.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Session;
use Martin\Forms\Classes\BackendHelpers;
use Martin\Forms\Models\Settings;
use BlakeJones\MagicForms\Classes\BackendHelpers;
use BlakeJones\MagicForms\Models\Settings;
use RainLab\Translate\Classes\Translator;

trait ReCaptcha {
Expand Down
4 changes: 2 additions & 2 deletions classes/ReCaptchaValidator.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Request;
use Martin\Forms\Models\Settings;
use BlakeJones\MagicForms\Models\Settings;

class ReCaptchaValidator {

Expand Down
8 changes: 4 additions & 4 deletions classes/SendMail.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Martin\Forms\Classes;
namespace BlakeJones\MagicForms\Classes;

use Mail;
use System\Models\MailTemplate;
use Martin\Forms\Classes\BackendHelpers;
use BlakeJones\MagicForms\Classes\BackendHelpers;

class SendMail {

Expand All @@ -23,7 +23,7 @@ public static function sendNotification($properties, $post, $record, $files) {
if (is_array($properties['mail_recipients']) || is_array($properties['mail_bcc'])) {

// CUSTOM TEMPLATE
$template = isset($properties['mail_template']) && $properties['mail_template'] != '' && MailTemplate::findOrMakeTemplate($properties['mail_template']) ? $properties['mail_template'] : 'martin.forms::mail.notification';
$template = isset($properties['mail_template']) && $properties['mail_template'] != '' && MailTemplate::findOrMakeTemplate($properties['mail_template']) ? $properties['mail_template'] : 'blakejones.magicforms::mail.notification';

$data = [
'id' => $record->id,
Expand Down Expand Up @@ -122,7 +122,7 @@ public static function sendAutoResponse($properties, $post, $record) {
if (filter_var($to, FILTER_VALIDATE_EMAIL) && filter_var($from, FILTER_VALIDATE_EMAIL)) {

// CUSTOM TEMPLATE
$template = isset($properties['mail_resp_template']) && $properties['mail_resp_template'] != '' && MailTemplate::findOrMakeTemplate($properties['mail_resp_template']) ? $properties['mail_resp_template'] : 'martin.forms::mail.autoresponse';
$template = isset($properties['mail_resp_template']) && $properties['mail_resp_template'] != '' && MailTemplate::findOrMakeTemplate($properties['mail_resp_template']) ? $properties['mail_resp_template'] : 'blakejones.magicforms::mail.autoresponse';

Mail::sendTo($to, $template, [
'id' => $record->id,
Expand Down
Loading