Comments (4)
The reason that EVENT_REGISTER_VARIABLES
has no context is that the values are static, but I can see what - if anything - we can do about that.
from formie.
This probably has to do with restricting Twig functionality due to some security concerns we're using a sandbox with limited functionality, but it is strange you mentioned this is working on 2.1.13 and it's a Craft version that's triggering things.
I think in this case you might need to register a new variable via PHP, rather than writing Twig. It's probably our preference as well, as the whole concept of Formie is to keep things friendly for novice users (even if this form might just be for yourself).
use verbb\formie\helpers\Variables;
use verbb\formie\events\RegisterVariablesEvent;
use yii\base\Event;
Event::on(Variables::class, Variables::EVENT_REGISTER_VARIABLES, function(RegisterVariablesEvent $event) {
$event->variables['custom'][] = [
'label' => 'Custom',
'heading' => true,
];
$event->variables['custom'][] = [
'label' => 'Entry Title',
'value' => 'Some Example Title',
];
});
Here, this adds a new option to the variable-picker dropdown of your choosing. Now that might be tricky considering you want some context of the form you're currently on, so that might not work for you.
As an alternative, you can keep the Twig that you have now, but add some exceptions to the Twig Sandbox to allow some things.
use craft\elements\db\ElementQuery;
use verbb\formie\Formie;
use verbb\formie\events\ModifyTwigEnvironmentEvent;
use yii\base\Event;
Event::on(Formie::class, Formie::EVENT_MODIFY_TWIG_ENVIRONMENT, function(ModifyTwigEnvironmentEvent $event) {
$event->allowedMethods[ElementQuery::class] = 'one';
});
Here, we state with class and methods to allow. You might even need to add your module's method. I know that's a bit more of a pain, but it's a pretty valid security concern if we allow any Twig to be written in fields, as it can be very easily exploited. So most advanced things are opt-in.
Refer to the docs
Both of these events will be available for the next release. To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.13"
.
from formie.
This is great, thanks!
Variant 1)
This is really useful. I would love to use this way, but as you stated, I would need the context. Is there any way that I can refer to the values from the submitted fields? Or the submission ID at least, so that I can query for the submission and get the entry value from it?
This would be a very user friendly way to use those custom variables instead of the inline Twig code.
Variant 2)
Used that one for the moment and this works great:
Event::on(Formie::class, Formie::EVENT_MODIFY_TWIG_ENVIRONMENT, function(ModifyTwigEnvironmentEvent $event) {
$event->allowedMethods[ParagrapheinsModuleVariable::class] = 'getinhouseinvitationparts';
$event->allowedMethods[ElementQuery::class] = 'one';
});
from formie.
That would be pretty neat, because the most useful variables that are selectable in the drop down are dynamic values from the populated form fields. Thanks for the effort!
from formie.
Related Issues (20)
- [2.x]: Issue with summary and field name HOT 5
- [2.x]: Translation problem with subfield prefix and mail var `All Form Fields` HOT 2
- [3.x]: Issue with option `required field` for field date HOT 2
- Formie Import does not delete notifications HOT 1
- `not_authed` error with Slack integration HOT 4
- Name field does not render in preview email notification, nor does it get send in the email notification HOT 2
- Element Integration - Entry field issue HOT 6
- Address -> Country field isn't saving HOT 2
- [2.x] Translate issue frontend validation. HOT 3
- Payment Field: Stripe: Hide Postal Code setting not respected HOT 1
- Customer name and Email IDs not displaing in the Stripe dashboard HOT 1
- Add GoCardless Payment integration
- Recaptcha & Payments HOT 4
- Shortest Data Retention possible HOT 3
- Encrypted phone number exceeds 255 character limit HOT 2
- Form submission error when radio button's value is over a certain length HOT 2
- Bug: number doesn't respect max value HOT 2
- Entries field - enable sorting entries by structure order HOT 4
- More Top Level controls HOT 1
- User Registration Integration password isn't set correctly HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formie.