Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

anton-mellit
Copy link

Any form field can be equipped with the following:

process:
    twig: some twig markup goes here

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

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 }}.

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.

```
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 }}
@mahagr mahagr requested a review from rhukster April 23, 2020 08:44
switch ($action) {
case 'process':
$this->process($form);
Copy link
Member

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.

@anton-mellit
Copy link
Author

anton-mellit commented Apr 24, 2020 via email

@rhukster
Copy link
Member

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.

@mahagr
Copy link
Member

mahagr commented May 4, 2020

What I've done in the past was to check something like: if process exists, do the processing in its turn and flag that it has been used. At the end of the loop check the variable and do processing in a backwards-compatible way.

@ricardo118
Copy link
Contributor

the way i usually achieve this functionality is simply with js on form submit()

@NicoHood
Copy link
Contributor

Are there any updates on this?

@anton-mellit Which comments plugin bug are you referring to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants