Express form, how to change the subject?

I’d like to change the subject of the form, the first part is always fixed. Can someone please explain which file to change/duplicate? Thanks!

Hi @Dutchwave - so are you talking about the subject of the email confirmation the form sends out, that’s what you’d like to change?

Hi @EvanCooper. Yes when you enter an optional mailaddress in the field:
Send form submissions to email addresses

You can simply copy the file concrete\mail\block_express_form_submission.php, put it in application\mail\block_express_form_submission.php and modify this line to your liking:

$subject = t(‘Website Form Submission – %s’, $formName);

2 Likes

Hi all,

Reviving an old topic, but it seems to be on track of what I need to achieve.

I have an express form for contact, containing every fields including a dropdown for the user to select a type of enquiry, a subject text field and other fields (not relevant for this question)

Is there a way for the generated email’s subject line to take the values from the two fields and output something like

“New message from website - [enquiry] - [subject]”

I managed the following code, but somehow the values are note retrieved:

$enquiry = isset($_POST['akID'][36]['atSelectOptionValue']) ? $_POST['akID'][36]['atSelectOptionValue'] : 'Unknown';
$formSubject = isset($_POST['akID[34][value]']) ? $_POST['akID[34][value]'] : 'No Subject';
$subject = t('New message from website - [%s] - [%s]', $enquiry, $formSubject);

Here is the HTML output of the relevant fields from the Express form module

<div class="mb-3">
  <label class="form-label" for="akID[36][atSelectOptionValue]">enquiry</label>
  <span class="text-muted small">Required</span>
  <select id="akID[36][atSelectOptionValue]" name="akID[36][atSelectOptionValue]" class="form-select" required="required">
    <option value="" disabled="disabled" selected="selected">enquiry*</option>
    <option value="24">studio</option>
    <option value="25">commission</option>
    <option value="26">press</option>
  </select>
</div>
<div class="mb-3">
  <label class="form-label" for="akID[34][value]">subject</label>
  <span class="text-muted small">Required</span>
  <input type="text" id="akID[34][value]" name="akID[34][value]" value="" placeholder="subject*" class="form-control ccm-input-text" required="required">
</div>

Thank you very much for your help !

-Quentin

I’m assuming you are modifying the email template found in concrete\mail\block_express_form_submission.php

If you look below where the subject is defined you can see a foreach loop going through each attribute and its value. You could modify that code to get the correct attributes:

foreach ($attributes as $value) {
    $attributeKey = $value->getAttributeKey();
    $akID = $attributeKey->getAttributeKeyID();
    $akHandle = $attributeKey->getAttributeKeyHandle();
    // use those to check for the proper attribute and use the value like so:
    $text= $value->getPlainTextValue();
}

You could either check for $akID being equal to 34 or 36 as in your example but that means you’d have to modify your code if you ever delete thes 2 attributes and replace them with others.

If you created the form directly from the form block, using handle won’t work reliably. But if you created an Express entity from the dashboard and then added it to the page with the Form block, it is you’re most reliable option.

I hope this helps.

Thank you for the explanation !

With a little adjustment, it did the trick just as I needed :slight_smile:

Although it would be nice in the future if this could become a feature in the Form module options to adjust the subject line. But that’s another topic.

Thank you very much anyways !

Always happy to help :blush: