-
Notifications
You must be signed in to change notification settings - Fork 79
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
Ability to overwrite fields after the form is submitted, but before actions are taken. #419
base: develop
Are you sure you want to change the base?
Conversation
``` process: twig: some twig markup goes here ``` Additionally, form is equipped with a new action "process". When process action is called, all process:twig contents of all fields are evaluated the results are saved in the values of these fields. For instance ``` form: fields: - type: hidden name: path process: twig: "/blog/{{ grav.page.folder }}" process: - process: true - addComment: true ``` After the form is submitted, before saving the comment the field "path" is evaluated to /blog/{{ grav.page.folder }}
switch ($action) { | ||
case 'process': | ||
$this->process($form); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears with your change, the form will only be processed IF it has a:
process:
process: true
...
This would mean that all existing forms would no longer automatically process the fields.. Granted we currently only support the fillWithCurrentDateTime
task, but still, it would not work until the form blueprint was updated.
You are right, but actually this change has nothing to do with the new
functionality.
The old way `$this->process($form)` was called is broken and I wasn't sure
what's the better way to fix it.
At the moment `$this->process($form)` is called **every time we process an
action in form.php**. In particular:
- it may get called several times. This won't create problems, but this is
clearly not the way it is intended to work
- if an action implemented in a different plugin comes first, that action
will run before `process($form)` is called,
for instance if `add_page` is called as the first action we won't see the
result of `fillWithCurrentDateTime`
I guess, the right place to call `$this->process($form)` would be after all
the validations
and before all the actions. Maybe it should be a validation? But I am not
sure where exactly to place it.
…On Thu, Apr 23, 2020 at 10:33 PM Andy Miller ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In form.php
<#419 (comment)>
:
> switch ($action) {
+ case 'process':
+ $this->process($form);
It appears with your change, the form will only be processed *IF* it has
a:
process:
process: true
...
This would mean that all existing forms would no longer automatically
process the fields.. Granted we currently only support the
fillWithCurrentDateTime task, but still, it would not work until the form
blueprint was updated.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#419 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APCSZUZFRS4SDSASPRKSLO3ROCQ2HANCNFSM4MGPCULA>
.
|
Let me think about this over the weekend. I would like to find a better way to move forward with more flexibility but at the same time be backwards compatible. |
What I've done in the past was to check something like: if |
the way i usually achieve this functionality is simply with js on form submit() |
Are there any updates on this? @anton-mellit Which comments plugin bug are you referring to? |
Any form field can be equipped with the following:
Additionally, form is equipped with a new type of action "process". When process action is called, all process:twig contents of all fields are evaluated and the results are saved in the values of these fields. For instance
After the form is submitted, before saving the comment the field "path" is evaluated to /blog/{{ grav.page.folder }}.
This helps to resolve a bug in comments plugin. This can also be used to automatically save date, username and other things in add-page-by-form plugin.