(Grav GitSync) Automatic Commit from exu
This commit is contained in:
parent
fcb9c420e8
commit
5332198df2
@ -1,3 +1,13 @@
|
|||||||
|
# v7.4.0
|
||||||
|
## 03/29/2024
|
||||||
|
|
||||||
|
1. [](#improved)
|
||||||
|
* Better modular form support
|
||||||
|
* Support for multiple Ajax/XHR forms on a single page either modular-based or manually injected
|
||||||
|
* Yarn libraries updated
|
||||||
|
1. [](#bugfix)
|
||||||
|
* Fixed an issue with cache being tied to `core` cache_id rather than the more appropriate `pages` cache_id, which could lead to form properties being cached even when modified.
|
||||||
|
|
||||||
# v7.3.0
|
# v7.3.0
|
||||||
## 12/14/2023
|
## 12/14/2023
|
||||||
|
|
||||||
|
257
plugins/form/assets/form.min.js
vendored
257
plugins/form/assets/form.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
24
plugins/form/assets/xhr-submitter.js
Normal file
24
plugins/form/assets/xhr-submitter.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
function attachFormSubmitListener(formId) {
|
||||||
|
var form = document.getElementById(formId);
|
||||||
|
if (!form) {
|
||||||
|
console.warn('Form with ID "' + formId + '" not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
form.addEventListener('submit', function(e) {
|
||||||
|
// Prevent standard form submission
|
||||||
|
e.preventDefault();
|
||||||
|
// Submit the form via Ajax
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open(form.getAttribute('method'), form.getAttribute('action'));
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
|
xhr.onload = function() {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
form.innerHTML = xhr.responseText; // Update the current form's innerHTML
|
||||||
|
} else {
|
||||||
|
// Handle HTTP error responses (optional)
|
||||||
|
console.error('Form submission failed with status: ' + xhr.status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(new URLSearchParams(new FormData(form)).toString());
|
||||||
|
});
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
name: Form
|
name: Form
|
||||||
slug: form
|
slug: form
|
||||||
type: plugin
|
type: plugin
|
||||||
version: 7.3.0
|
version: 7.4.0
|
||||||
description: Enables forms handling and processing
|
description: Enables forms handling and processing
|
||||||
icon: check-square
|
icon: check-square
|
||||||
author:
|
author:
|
||||||
@ -103,6 +103,18 @@ form:
|
|||||||
validate:
|
validate:
|
||||||
type: bool
|
type: bool
|
||||||
|
|
||||||
|
modular_form_fix:
|
||||||
|
type: toggle
|
||||||
|
label: PLUGIN_FORM.MODULAR_FORM_FIX
|
||||||
|
help: PLUGIN_FORM.MODULAR_FORM_FIX_HELP
|
||||||
|
highlight: 1
|
||||||
|
default: 1
|
||||||
|
options:
|
||||||
|
1: PLUGIN_ADMIN.ENABLED
|
||||||
|
0: PLUGIN_ADMIN.DISABLED
|
||||||
|
validate:
|
||||||
|
type: bool
|
||||||
|
|
||||||
files:
|
files:
|
||||||
type: section
|
type: section
|
||||||
title: PLUGIN_FORM.FILES
|
title: PLUGIN_FORM.FILES
|
||||||
|
@ -1299,7 +1299,10 @@ class FormPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
/** @var \Grav\Common\Cache $cache */
|
/** @var \Grav\Common\Cache $cache */
|
||||||
$cache = $this->grav['cache'];
|
$cache = $this->grav['cache'];
|
||||||
$cache_id = $cache->getKey() . '-form-plugin';
|
/** @var Pages $pages */
|
||||||
|
$pages= $this->grav['pages'];
|
||||||
|
// $cache_id = $cache->getKey() . '-form-plugin';
|
||||||
|
$cache_id = $pages->getPagesCacheId() . '-form-plugin';
|
||||||
return $cache_id;
|
return $cache_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ refresh_prevention: false
|
|||||||
client_side_validation: true
|
client_side_validation: true
|
||||||
debug: false
|
debug: false
|
||||||
inline_errors: false
|
inline_errors: false
|
||||||
|
modular_form_fix: true
|
||||||
files:
|
files:
|
||||||
multiple: false # To allow multiple files, default is single
|
multiple: false # To allow multiple files, default is single
|
||||||
limit: 10 # Number of allowed files per field (multiple required)
|
limit: 10 # Number of allowed files per field (multiple required)
|
||||||
|
@ -88,6 +88,8 @@ en:
|
|||||||
BASIC_CAPTCHA_MATH_MAX: "Maximum number"
|
BASIC_CAPTCHA_MATH_MAX: "Maximum number"
|
||||||
BASIC_CAPTCHA_MATH_OPERATORS: "Mathematical operators (randomized)"
|
BASIC_CAPTCHA_MATH_OPERATORS: "Mathematical operators (randomized)"
|
||||||
TURNSTILE_CAPTCHA: "Cloudflare Turnstile Captcha"
|
TURNSTILE_CAPTCHA: "Cloudflare Turnstile Captcha"
|
||||||
|
MODULAR_FORM_FIX: "Modular Form Fix"
|
||||||
|
MODULAR_FORM_FIX_HELP: "Fixes the issue with modular forms not finding the correct form automatically"
|
||||||
|
|
||||||
eu:
|
eu:
|
||||||
PLUGIN_FORM:
|
PLUGIN_FORM:
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
"gulp-clean-css": "^4.3.0",
|
"gulp-clean-css": "^4.3.0",
|
||||||
"gulp-csscomb": "^3.1.0",
|
"gulp-csscomb": "^3.1.0",
|
||||||
"gulp-rename": "^2.0.0",
|
"gulp-rename": "^2.0.0",
|
||||||
"gulp-sass": "^4.0.2",
|
|
||||||
"gulp-sourcemaps": "^2.6.5",
|
|
||||||
"gulp-webpack": "^1.5.0",
|
"gulp-webpack": "^1.5.0",
|
||||||
"immutable": "^4.0.0-rc.12",
|
"immutable": "^4.0.0-rc.12",
|
||||||
"imports-loader": "^0.8.0",
|
"imports-loader": "^0.8.0",
|
||||||
|
@ -1,21 +1,8 @@
|
|||||||
{% if form.xhr_submit == true %}
|
{% if form.xhr_submit == true %}
|
||||||
|
{% do assets.addJs('plugin://form/assets/xhr-submitter.js', {'group': 'bottom', 'position': 'before'}) %}
|
||||||
{% do assets.addInlineJs("
|
{% do assets.addInlineJs("
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
var form = document.getElementById('" ~ form.id ~ "');
|
attachFormSubmitListener('" ~ form.id ~ "');
|
||||||
form.addEventListener('submit', function(e) {
|
});",
|
||||||
// prevent standard form submission
|
{'group': 'bottom', 'position': 'before'}) %}
|
||||||
e.preventDefault();
|
|
||||||
// submit the form via Ajax
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open(form.getAttribute('method'), form.getAttribute('action'));
|
|
||||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
||||||
xhr.onload = function() {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
document.getElementById('" ~ form.id ~ "').innerHTML = xhr.responseText;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.send(new URLSearchParams(new FormData(form)).toString());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
", {'group': 'bottom', 'position': 'before', 'priority': 100}) %}
|
|
||||||
{% endif %}
|
{% endif %}
|
@ -1,4 +1,8 @@
|
|||||||
<div class="modular-row form {{ page.header.class }}">
|
<div class="modular-row form {{ page.header.class }}">
|
||||||
{{ content|raw }}
|
{{ content|raw }}
|
||||||
|
{% if config.plugins.form.modular_form_fix %}
|
||||||
|
{% include "forms/form.html.twig" with {form: forms({route: page.route})} %}
|
||||||
|
{% else %}
|
||||||
{% include "forms/form.html.twig" %}
|
{% include "forms/form.html.twig" %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user