ekke
April 1, 2020, 2:46pm
1
My idea is: Let’s finally allow Mautic users to use calculated values in campaign steps. E.g.
“Update contact field with current time & date” or maybe even
“Update contact field with value from elsewhere (e.g. from a different field)”
and maybe beyond contact data
Not sure if we should start with the most important flavours, “hard-coded” - or if we should come up with a sophisticated general framework. Maybe we can fid something in between.
I think these groups of people would benefit from this idea:
Why I think they would benefit from this idea:
Any code or resources to support this idea:
Are you willing to work on this idea?: Yep
What skills and resources do you need to explore this further?
This would be a great feature.
Some of the use cases of calculated fields I can think about are as follows:
A formula field that could do a timestamp on a field when another field changes
A formula field that could follow a logic of if, then…
A formula that could do math operation (+,-,*,/) as well as functions like SUM, AVG, MEAN, MEDIAN
I am in need of (+,-,*,/) fields. Anyone have a solution for this?
1 Like
This would be a very nice feature.
@ekke we discussed this in the release planning meeting - some of these features are implemented for forms:
5.x ← putzwasser:5.x-feat-dynamic-date-form-fields
opened 12:05AM - 09 Sep 24 UTC
| Q | A
| --------------------------------… ------ | ---
| Bug fix? (use the a.b branch) | 🔴
| New feature/enhancement? (use the a.x branch) | 🟢
| Deprecations? | 🟢
| BC breaks? (use the c.x branch) | 🔴
| Automated tests included? | 🟢
| Related user documentation PR URL | https://github.com/mautic/user-documentation/pull/317
| Related developer documentation PR URL | mautic/developer-documentation-new#...
| Issue(s) addressed | Fixes #...
## Description
This PR adds the possibility to add dynamic date time values as **default value** to `date`, `datetime` and `hidden` input fields.
You can use any string described in https://www.php.net/manual/en/datetime.formats.php for setting dynamic date values.
#### For `date` and `datetime` fields
For `date` and `datetime` fields Mautic will try to parse any string as a date. The only exception is an empty string (which PHP would normally parse as `now`. If parsing fails the default value will be left as-is.
- Default values for `date` fields will be formatted in `Y-m-d`.
- Default values for `datetime` fields will be formatted in `Y-m-d\TH:i`.
**Example:**
- `now`
- `today +2 days 4am`
- `2025-05-04 `
- `2025-05-04 14:30`
#### For `hidden` fields
For `hidden` fields Mautic will try to parse any (non-empty) string as a date **if it ends with `|date`**. Adding this (twig-like) suffix was done to prevent accidentally parsing meaningful strings as date. For example a hidden field with `4am` might bear some meaning besides referring to `today at 04:00`.
- Default values for `hidden` fields will be formatted in `Y-m-d\TH:i`. There is no option to change this.
If parsing fails the default value will be left as-is.
**Example:**
- `now|date`
- `today +2 days 4am|date`
- `2025-05-04 |date`
- `2025-05-04 14:30|date`
## Use cases
- Setting relative dates in input fields
- Recording the date and time a form was submitted in a custom contact field
---
### 📋 Steps to test this PR:
1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs [here](https://contribute.mautic.org/contributing-to-mautic/tester))
2. Create or edit a form
3. Add date, datetime or hidden input fields
4. Set the default value to any datetime parsable string. Append `|date` for hidden fields.
5. Open the form and inspect the html code
6. See that the default values are replaced by actual date time values
So we could perhaps repurpose some of this.
Is it still a feature you’re looking for Mautic to implement?