Hallo
Ich nutze Visforms 4.1.7 / 4.1.4 auf Joomla 4.1.5.
Alles funktioniert soweit gut.
Nun wollte ich anfangen, ein Custom Plg zu nutzen (auf Basis von PlgMaster 4.0.0), um meinen Formularen eigene Logik einzuhauchen.
Bei ersten Test habe ich festgestellt, dass der Event onVisformsFormPrepare problemlos triggert, onVisformsBeforeFormSave aber nicht. Das sehe ich ganz einfach daran, dass eingebaute Test-Meldungen (echo, consol.log ...) bei onVisformsFormPrepare sauber ausgegeben werden, bei onVisformsBeforeFormSave nicht.
Irgendeine Idee, woran das liegen könnte?
Hier mein Custom Plugin, basierend auf PlgMaster:
Code:
<?php
/**
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
class plgVisformsCustom extends CMSPlugin
{
public function __construct(& $subject, $config) {
parent::__construct($subject, $config);
//load the translation
$this->loadLanguage();
}
// NOTE: this plugin requires Visforms Base and Visforms Subscription 4.1.0 (or higher) !!
public function onVisformsFormPrepare($context, $form, $menuparams) {
// Skip plugin if context is wrong
$allowedContexts = array('com_visforms.form', 'mod_visforms.form', 'plg_vfformview.form');
if (!in_array($context, $allowedContexts)) {
return true;
}
$app = Factory::getApplication();
// only perform action, if we are in front end
if ($app->isClient('administrator')) {
return true;
}
//if $form->parentFormId is not set, Visforms or Content Plugin Form View version is to old
if (!isset($form->parentFormId)) {
return true;
}
// get value of id attribute of the form which is going to be displayed
$parentFormId = $form->parentFormId;
// add custom submit handler function to the form
echo "Triggered by onVisformsFormPrepare";
$script = 'jQuery(document).ready(function () {
//add custom submit action function to form
console.log("Triggered by onVisformsFormPrepare");
alert("Triggered by onVisformsFormPrepare");
});';
Factory::getDocument()->addScriptDeclaration($script);
// End: add custom submit handler function to the form
}
public function onVisformsBeforeFormSave($context, $form, $fields)
{
// Skip plugin if context is wrong
$allowedContexts = array('com_visforms.form', 'mod_visforms.form', 'plg_vfformview.form');
if (!in_array($context, $allowedContexts)) {
return true;
}
$app = Factory::getApplication();
// only perform action, if we are in front end
if ($app->isClient('administrator')) {
return true;
}
// your code in here
echo "Triggered by onVisformsBeforeFormSave";
$script = 'jQuery(document).ready(function () {
console.log("Triggered by onVisformsBeforeFormSave");
alert("Triggered by onVisformsBeforeFormSave");
});';
Factory::getDocument()->addScriptDeclaration($script);
return true;
}
}