Developer forum

Forum » Development » Dynamic topic field in email

Dynamic topic field in email

Marc Hjorth
Marc Hjorth
Reply

I'm sending a mail to a user through a form. I pasted a part of the template below. The template is a part of a Forms for editors-module.

I figured out you can control the topic, by using a hidden field like this:

<input type="hidden" name="ForgotPasswordMailSubject" value="Topic goes here" />


Here is the template I use

<form action="@formAction" class="@formCssClass" enctype="multipart/form-data" id="@formId" method="post" name="@formId" onsubmit="@formOnSubmit">
@formSystemFields

<div class="row">
    <div class="col-md-9 col-md-pull-3">
        <div class="form-group">
            <label>Foreningens navn</label>
            <input class="form-control" id="Foreningensnavn" name="Foreningensnavn" placeholder="" required="" type="text">
        </div> ...

 

I would like to use whatever the user types in the "Foreningsnavn" field, to be shown in the topic of the mail, is this possible?


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

If it is a custom template, you can add a bit of javascript to do that:

<input class="form-control" id="Foreningensnavn" name="Foreningensnavn" placeholder="" required="" type="text">
<input class="form-control" id="MailSubject" name="MailSubject" placeholder="" required="" type="text">

<script>
document.getElementById("Foreningensnavn").addEventListener("keyup", setSubject);

function setSubject() {
    var field = document.getElementById("Foreningensnavn");
    var subjectField = document.getElementById("MailSubject");
    subjectField.value = field.value;
}

</script>

Note: The hidden field should probably be called MailSubject and not ForgotPasswordMailSubject.

BR Nicolai
 

Votes for this answer: 1
 
Marc Hjorth
Marc Hjorth
Reply

Thanks for the answer, it almost works as intended.

The subject gets set to the value of field, but it also contains a comma in front of the subject, and I can't seem to figure out why.

var subjectField = document.getElementById("MailSubject");
subjectField.value = "some value";

Setting the subject like this also makes the "," appear in front of the subject.

 

Setting the subject to a static value like this however doesn't show a comma in the mail.

<input type="hidden" name="MailSubject" value="some value" />

Any ideas?

Thanks in advance

 
Marc Hjorth
Marc Hjorth
Reply

Figured it out.

You should make a hidden field from the forms for editors tool in the backend with the name "MailSubject".

 

You must be logged in to post in the forum