Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Handling reset button

Started by Richard Hainsworth 8 years ago · 1 replies · 910 views
8 years ago

I am writing a plugin to handle a sequential form, that is after pressing the Submit button, the user is redirected to the next page in a sequence, which in turn may contain form data.

Everything works as planned, except I now want a mechanism to cancel the sequence by using a 'reset' button.

FYI, the draft plugin is at https://github.com/finanalyst/grav-plugin-sequential-form . Once I get the reset button working, I will offer to republish it.

I cannot yet work out how to detect which button of a form was pressed (submit or reset). That is, in onFormProcessed, how can I detect the button that was pressed?

The aim would be to redirect to the first page in the sequence, stop form propagation, and reset the form data.

I am thinking that it will be necessary to add javascript to the form so that hitting reset sends a redirect to the first page.

I have studied form.php, anithubd the templates, and I can see button.task, but there is no documentation about what button.task does.

Also, I can see that blueprints are important. I was wondering whether I could use a rule to cancel data. However, there is no information about blueprints.

8 years ago

[SOLVED]
After some research about html forms and looking at the form twig templates, my solution is

  • Include a new button into the page form yaml,
  • set the type to 'submit'
  • set the attribute 'task' of the button to a new value, eg,. 'mybutton', viz.
    YAML
    form:
    buttons:
    - type: submit
      value: Click here for another action
      task: mybutton
    
  • include in OnFormProcessed the lines:
    PHP
    if (isset($_POST['task']) && $_POST['task'] == 'mybutton' ) { do_stuff(); }
    

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago