diff --git a/CHANGES.rst b/CHANGES.rst index b5032c9..4867b94 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 2.7.1 (unreleased) ------------------ -- Configurable mail header and footer +- Configurable email subject. + [folix-01] + +- Configurable mail header and footer. [folix-01] 2.7.0 (2023-04-03) diff --git a/README.rst b/README.rst index 1c7c6ca..720d972 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ :target: https://pypi.python.org/pypi/collective.volto.formsupport :alt: Egg Status -.. image:: https://img.shields.io/pypi/pyversions/collective.volto.formsupport.svg?style=plastic +.. image:: https://img.shields.io/pypi/pyversions/collective.volto.formsupport.svg?style=plastic :target: https://pypi.python.org/pypi/collective.volto.formsupport/ :alt: Supported - Python Versions @@ -197,6 +197,11 @@ By default this is not set. The upload limit is also passed to the frontend in the form data with the `attachments_limit` key. +Email subject templating +======================== +You can also interpolate the form values to email subject using the field id, in this way: ${123321123} + + Content-transfer-encoding ========================= diff --git a/src/collective/volto/formsupport/restapi/services/submit_form/post.py b/src/collective/volto/formsupport/restapi/services/submit_form/post.py index e72d255..ea57d59 100644 --- a/src/collective/volto/formsupport/restapi/services/submit_form/post.py +++ b/src/collective/volto/formsupport/restapi/services/submit_form/post.py @@ -220,11 +220,25 @@ def get_bcc(self): bcc.append(data["value"]) return bcc - def send_data(self): + def get_subject(self): subject = self.form_data.get("subject", "") or self.block.get( "default_subject", "" ) + for i in self.form_data.get("data", []): + field_id = i.get("field_id") + + if not field_id: + continue + + subject = subject.replace("${" + i.get("field_id") + "}", i.get("value")) + + return subject + + def send_data(self): + + subject = self.get_subject() + mfrom = self.form_data.get("from", "") or self.block.get("default_from", "") mreply_to = self.get_reply_to()