Joomla 5 Notice

We are pleased to announce that as of January 29, 2024, all of our Joomla extensions are compatible with Joomla 5.

For all who are still updateing from Joomla 3 to Joomla 4: Joomla 4 Migration instructions are available here:

There is now a separate Documentation for Visforms for Joomla 4 and for Visforms for Joomla 5!

Forum

Visforms Subscription user can ask questions in our forum. Please log in with the relevant user first.
Everybody can access the forum for reading.

Please only ask 1 question per topic.

Custom Code Plugin - Event onVisformsBeforeFormSave wird nicht getriggert

More
1 year 8 months ago #8304 by tornado
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;     }      }
 

More
1 year 8 months ago #8305 by Administrator AV
Hallo,
das Event onVisformsBeforeFormSave wird getriggert und zwar vom VisformsController aus, nachdem das Formular abgeschickt wurde.

Da nach dem Absenden des Formulars ganz am Ende immer noch ein Redirect erfolgt (auf die Erfolgsseite oder die Startseite oder zurück zum Formular, je nachdem was du im Formular auf dem Reiter "Ergebnis" konfiguriert hast, kommt ein Text den du mit der echo-Funktion ausgibst niemals an die Oberfläche.

D.h. du kannst mit Echo an dieser Stelle nicht testen, ob das Event getriggered wird.

Du müsstest
Code:
$app->enqueueMessage('Nachricht');
verwenden.

Gruß,
Aicha

:idea: I recommend you the new and up-to-date documentation for Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/en/docs/
Most of this also applies retrospectively to Joomla 3.
Please only ask 1 question per topic :-).

:idea: Ich empfehle Dir die neue und aktuelle Dokumentation für Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/docs/
Das meiste gilt rückwirkend auch für Joomla 3.
Bitte immer nur 1 Frage pro Thema stellen :-).

More
1 year 8 months ago #8306 by tornado
Hallo Aicha,
Das ist mir jetzt aber echt peinlich...
Hätte ich selber drauf kommen können.

Herzlichen Dank für deine rasche Unterstützung.

Grüsse,
Felix

Moderators: Administrator AVAdministrator IV
Powered by Kunena Forum