kitzberger / form-mailtext

TYPO3 extension to enhance EXT:form by custom mail texts per form plugin
7 stars 5 forks source link

Allow variable based conditions in mail text #9

Closed tillschweneker closed 2 years ago

tillschweneker commented 2 years ago

When using the extension it is possible to return the content of single form fields by adding the form field identifier to the mail text, e.g. Hello Mr./Mrs. {text-1}

To allow the editors to create dynamic mail texts, based on the users' input, it would be nice to be able to conditionally output text, based on the content of an input variable.

The examples are based on the handlebars syntax, maybe fluid conditions are easier to implement, though.

The conditions should handle values from text fields, select fields, checkboxes and radio buttons. They should allow nesting as well, e.g.

{{#if condition-1}}
     Lorem ipsum dolor sit amet.
     {{#if condition-2}}
          Nullam quis risus eget urna mollis ornare vel eu leo.
     {{/if}}
{{/if}}

Example:

The form has the following fields:

The editor wants to send a dynamic text to the user, based on the filled out form fields.

Mailtext:

Hello {text-1} {text-2},

thank you for your message, we will contact you as soon as possible.

{{#if checkbox-1 }}
We will send you additional information in a separate email. 
{{/if}}
kitzberger commented 2 years ago

@tillschweneker, please have a look at the first draft of that feature. It's based on regex though I doubt it already supports nested conditions.

tillschweneker commented 2 years ago

@kitzberger It works 🎉

Nesting is not working (as expected) and it is not easily possible to check if a value is empty.

kitzberger commented 2 years ago

@tillschweneker, I've just added comparisons with empty values and 'in array'. What do you think?

tillschweneker commented 2 years ago

@kitzberger It works like a charm 🤙

Now we just need nesting and maybe an {else} part. #gettinggreedy

tillschweneker commented 2 years ago

Oh @kitzberger, I missed something and I don't know if it has anything to do with the current changes. When I place {multiselect-1} in the mail output (not in an if condition) I get this error:

image

kitzberger commented 2 years ago

@tillschweneker, {else} should be easy to implement, but nested conditions, phewww ;-(

tillschweneker commented 2 years ago

No nesting is no problem @kitzberger

kitzberger commented 2 years ago

When I place {multiselect-1} in the mail output (not in an if condition) I get this error:

guess that's due to multiselect-1 being an array. you need to run it through some kind of foreach-thiny... that we don't have (yet)

kitzberger commented 2 years ago

@tillschweneker, 'else' is now implemented.

tillschweneker commented 2 years ago

@kitzberger Nice one! It works as well. I think we are done, are we?

kitzberger commented 2 years ago

@tillschweneker, just released version 2.1.0 on packagist and TER. Thanks for your input ;-)