From f4b183039b76db226365bbab10453f343f30cd4e Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 25 Nov 2021 12:23:10 +0100 Subject: [PATCH 1/4] DOCS: Add tutorials for honeypot and conditional fields --- Documentation/Tutorials/ConditionalFields.md | 36 +++++++++++ Documentation/Tutorials/HoneypotField.md | 66 ++++++++++++++++++++ README.md | 2 + 3 files changed, 104 insertions(+) create mode 100644 Documentation/Tutorials/ConditionalFields.md create mode 100644 Documentation/Tutorials/HoneypotField.md diff --git a/Documentation/Tutorials/ConditionalFields.md b/Documentation/Tutorials/ConditionalFields.md new file mode 100644 index 0000000..909b5cd --- /dev/null +++ b/Documentation/Tutorials/ConditionalFields.md @@ -0,0 +1,36 @@ +# Conditional fields + +The data from previous steps can be used to only show field in certain conditions. + +``` +renderer = Neos.Fusion.Form:Runtime.RuntimeForm { + process { + content = afx` + + + + ` + } +} +``` + +If a field shall be always present but be required once other fields are filled the schema can be adjusted via @process and @if. + +``` +renderer = Neos.Fusion.Form:Runtime.RuntimeForm { + process { + schema { + conditionalField = ${Form.Schema.string()} + conditionalField.@process.makeRequired = ${value.isRequired()} + conditionalField.@process.makeRequired.@if.hasOtherValue = ${data.otherValue || request.arguments.otherValue} + } + } +} +``` + +The condition checks the submitted data from the current request `request.arguments.otherField` and the +successfully submitted data from previus requests `data.otherField`. diff --git a/Documentation/Tutorials/HoneypotField.md b/Documentation/Tutorials/HoneypotField.md new file mode 100644 index 0000000..9422261 --- /dev/null +++ b/Documentation/Tutorials/HoneypotField.md @@ -0,0 +1,66 @@ +# Honeypot fields + +Honeypot fields are invisible but may be filled by bots and help to identify spam. +In fusion forms they can be implemented by combining an invisible field with an validator +that verifies that the field honey was not filled. + +``` +renderer = Neos.Fusion.Form:Runtime.RuntimeForm { + process { + content = afx` + .... + + + + ` + schema { + ... + honey = ${Form.Schema.string().validator('StringLength', {minimum:0, maximum:0})} + } + } +} +``` + +If you want to handle the spam detection silently you may choose to still show the success message +but not trigger the email action. In this case instead of the validator a condition for actions may be used. + +``` +renderer = Neos.Fusion.Form:Runtime.RuntimeForm { + process { + content = afx` + .... + + + + ` + schema { + ... + honey = ${Form.Schema.string()} + } + } + action { + # the message is always shown + message { + type = 'Neos.Fusion.Form.Runtime:Message' + options.message = ${q(node).property('message')} + } + # but the mail is only sent if no honey is found + email { + @if.noHoney = ${data.honey ? false : true} + type = 'Neos.Fusion.Form.Runtime:Email' { + ... + } + } + } +} +``` diff --git a/README.md b/README.md index e413d64..d948dc1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ be implemented like this. - [Runtime Fusion Form Basics](Documentation/RuntimeFormBasics.md) - Tutorials - [Custom form action](Documentation/Tutorials/CustomFormAction.md) + - [Honeypot field](Documentation/Tutorials/HoneypotField.md) + - [Conditional fields](Documentation/Tutorials/ConditionalFields.md) - Examples - [SingleStepForm](Documentation/Examples/SingleStepForm.md) - [MultiStepForm](Documentation/Examples/MultiStepForm.md) From 5b5aaf18eef6a3d00f74909d6804dabe63516663 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 25 Nov 2021 13:09:13 +0100 Subject: [PATCH 2/4] Update Documentation/Tutorials/ConditionalFields.md Co-authored-by: Jon Uhlmann --- Documentation/Tutorials/ConditionalFields.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Tutorials/ConditionalFields.md b/Documentation/Tutorials/ConditionalFields.md index 909b5cd..de727e3 100644 --- a/Documentation/Tutorials/ConditionalFields.md +++ b/Documentation/Tutorials/ConditionalFields.md @@ -1,6 +1,6 @@ # Conditional fields -The data from previous steps can be used to only show field in certain conditions. +The data from previous steps can be used to only show fields in certain conditions. ``` renderer = Neos.Fusion.Form:Runtime.RuntimeForm { From 1d15bb98eec3ae4f357577288624f0b1b573b6d4 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 25 Nov 2021 13:52:06 +0100 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Jon Uhlmann --- Documentation/Tutorials/ConditionalFields.md | 4 ++-- Documentation/Tutorials/HoneypotField.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/Tutorials/ConditionalFields.md b/Documentation/Tutorials/ConditionalFields.md index de727e3..2af3543 100644 --- a/Documentation/Tutorials/ConditionalFields.md +++ b/Documentation/Tutorials/ConditionalFields.md @@ -18,7 +18,7 @@ renderer = Neos.Fusion.Form:Runtime.RuntimeForm { } ``` -If a field shall be always present but be required once other fields are filled the schema can be adjusted via @process and @if. +If a field shall always be present but required once other fields are filled, the schema can be adjusted via `@process` and `@if`. ``` renderer = Neos.Fusion.Form:Runtime.RuntimeForm { @@ -33,4 +33,4 @@ renderer = Neos.Fusion.Form:Runtime.RuntimeForm { ``` The condition checks the submitted data from the current request `request.arguments.otherField` and the -successfully submitted data from previus requests `data.otherField`. +successfully submitted data from previous requests `data.otherField`. diff --git a/Documentation/Tutorials/HoneypotField.md b/Documentation/Tutorials/HoneypotField.md index 9422261..9a15e42 100644 --- a/Documentation/Tutorials/HoneypotField.md +++ b/Documentation/Tutorials/HoneypotField.md @@ -1,8 +1,8 @@ # Honeypot fields Honeypot fields are invisible but may be filled by bots and help to identify spam. -In fusion forms they can be implemented by combining an invisible field with an validator -that verifies that the field honey was not filled. +In Fusion Form, they can be implemented by combining an invisible field with a validator +that verifies that the field `honey` was not filled. ``` renderer = Neos.Fusion.Form:Runtime.RuntimeForm { @@ -26,8 +26,8 @@ renderer = Neos.Fusion.Form:Runtime.RuntimeForm { } ``` -If you want to handle the spam detection silently you may choose to still show the success message -but not trigger the email action. In this case instead of the validator a condition for actions may be used. +If you want to handle the spam detection silently, you may still show the success message +but not trigger the email action. In this case, instead of the validator, a condition for actions may be used. ``` renderer = Neos.Fusion.Form:Runtime.RuntimeForm { From 302d17dfe54838ee155cef86df596657fe9dcbd9 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 25 Nov 2021 14:02:31 +0100 Subject: [PATCH 4/4] DOCS: Add example for conditional step --- ...lFields.md => ConditionalFieldsAndSteps.md} | 18 ++++++++++++++++++ README.md | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) rename Documentation/Tutorials/{ConditionalFields.md => ConditionalFieldsAndSteps.md} (75%) diff --git a/Documentation/Tutorials/ConditionalFields.md b/Documentation/Tutorials/ConditionalFieldsAndSteps.md similarity index 75% rename from Documentation/Tutorials/ConditionalFields.md rename to Documentation/Tutorials/ConditionalFieldsAndSteps.md index 2af3543..63684d0 100644 --- a/Documentation/Tutorials/ConditionalFields.md +++ b/Documentation/Tutorials/ConditionalFieldsAndSteps.md @@ -18,6 +18,24 @@ renderer = Neos.Fusion.Form:Runtime.RuntimeForm { } ``` +This also allows to make whole form steps conditional: + +``` +renderer = Neos.Fusion.Form:Runtime.RuntimeForm { + process = Neos.Fusion.Form:Runtime.MultiStepProcess { + steps { + address { + ... + } + visa { + @if.fromForeignGalaxy = ${data.galaxy != 'milkyway'} + ... + } + } + } +} +``` + If a field shall always be present but required once other fields are filled, the schema can be adjusted via `@process` and `@if`. ``` diff --git a/README.md b/README.md index d948dc1..7ee7f16 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ be implemented like this. - Tutorials - [Custom form action](Documentation/Tutorials/CustomFormAction.md) - [Honeypot field](Documentation/Tutorials/HoneypotField.md) - - [Conditional fields](Documentation/Tutorials/ConditionalFields.md) + - [Conditional fields and steps](Documentation/Tutorials/ConditionalFieldsAndSteps.md) - Examples - [SingleStepForm](Documentation/Examples/SingleStepForm.md) - [MultiStepForm](Documentation/Examples/MultiStepForm.md)