[SOLVED] Form Finisher with a redirect to a node


(MF Med) #1

Hi Guys,

i wanted to build a (MultiLanguage) Contact form with a finisher, forward to a node(site) (With an Identifier)

I did not find anything to do that, so I built my own finsher.

Here is my finisher code:

The code for the redirect is a bit tricky, is there any better solution? For example
$context = $this->contextFactory->create(
[
‘workspaceName’ => ‘live’,
‘dimensions’ => [ ‘language’ => [(string)$this->i18nService->getConfiguration()->getCurrentLocale()] ],
]
);

Thanks in Advanced!


(Bastian Waidelich) #2

You don’t need a custom finisher for that.
If you use neos/form-builder you can just use Fusion to set the uri option of the RedirectFinisher:

prototype(Some.ContactForm:Contact) < prototype(Neos.Form.Builder:Form) {

    @context.redirectUri = Neos.Neos:NodeUri {
        node = ${q(site).find('#some-identifier').get(0)}
    }

    presetName = 'bootstrap'
    firstPage {
        elements {
            name = Neos.Form.Builder:MultiLineText.Definition {
                label = 'Name'
            }
        }
    }
    finishers {
        redirectFinisher = Neos.Form.Builder:RedirectFinisher.Definition {
            options {
                uri = ${redirectUri}
            }
        }
    }
}

If you don’t use the form-builder package but define your forms via YAML you don’t have that flexibility directly, but you can use the overrideConfiguration property of the Form Prototype to achieve the same:

prototype(Neos.NodeTypes.Form:Form) {
    overrideConfiguration {
        renderables = Neos.Fusion:RawArray {
            finishers = Neos.Fusion:RawArray {
                # assumes that the RedirectFinisher is your first finisher!
                0 = Neos.Fusion:RawArray {
                    uri = Neos.Neos:NodeUri {
                        node = ${q(site).find('#some-identifier').get(0)}
                    }
                }
            }
        }
    }
}

(MF Med) #3

Thanks for your answer,
I tried that, but I do not get it like in your example

I become this error

Here is the Log file.

Here is my Code in root.fusion

prototype(Neos.NodeTypes.Form:Form) {
	overrideConfiguration {
		renderables = Neos.Fusion:RawArray {
			finishers = Neos.Fusion:RawArray {
				# assumes that the RedirectFinisher is your first finisher!
                0 = Neos.Fusion:RawArray {
					uri = Neos.Neos:NodeUri {
						node = ${q(site).find('#fde02d3f-6abc-4352-be2b-a1b8e04dcf9f').get(0)}
					}
				}
			}
		}
	}
}

And the Finisher

finishers:

Thanks for your reply


(Rene Rehme) #4

Im not sure but i think its uncached and you need to configure which context needs to be available. Try to add " site "

@cache {
    mode = 'uncached'
    context {
      1 = 'node'
      2 = 'documentNode'
      3 = 'site'
    }
  }

(Bastian Waidelich) #5

@mfmeds like @ReneC wrote you can add site to the context of Neos.NodeTypes.Form:Form.

Alternatively you can write

node = ${q(node).find('#fde02d3f-6abc-4352-be2b-a1b8e04dcf9f').get(0)}

above


(MF Med) #6

Thanks guys for your help,

@bwaidelich with node i become this error: Identifier not set.
do you have a full Example? i don’t can find the fail in my Contact Form.


(Bastian Waidelich) #7

Can you share the whole exception message and code?
I guess it is just the Form Framework complaining about a missing Form Element identifier and got nothing to do with the above.
What’s your form definition (YAML)?


(MF Med) #8

Here is my complete YAML file,

here the Exception:


and the Full log:

very thanks, best regards


(Bastian Waidelich) #9

@mfmeds I think my example above was not entirely correct

try this

prototype(Neos.NodeTypes.Form:Form) {
    overrideConfiguration {
        finishers = Neos.Fusion:RawArray {
            # assumes that the RedirectFinisher is your first finisher!
            0 = Neos.Fusion:RawArray {
                options = Neos.Fusion:RawArray {
                    uri = Neos.Neos:NodeUri {
                        node = ${q(node).find('#fde02d3f-6abc-4352-be2b-a1b8e04dcf9f').get(0)}
                    }
                }
            }
        }
    }
}

(MF Med) #10

Very Very Thanks @bwaidelich
this is all what i needed.
Works great now.