Sometimes you might want to add something to the beginning or end of your contact form subject line in order to create rules or filters in your email or help desk. This text is added to the beginning or end of the subject line after a reader clicks submit, so there's no chance that they could delete it or change it. They never know it's there, and you can set up email or help desk queue rules and filters to help process these submissions.
We like to use a code snippet added to the the Custom HTML to solve this problem. To set it up:
- Go to Library > Snippets.
- Select the + Create New Snippet button.
- Give your snippet a Name. This is how the snippet will appear in the Snippet Library and in snippet look-ups. The Merge Code Name will auto-generate from the Snippet Name, but you can edit it if you'd like to. For example: Contact Form Subject.
- Give your snippet a Description. This will help describe what your snippet does to other authors (and may help remind you if you forget!) For example: Add "Knowledge Base Request: " to the start of all contact form submissions.
- Click the dropdown next to Snippet Content to select the Code Editor.
- Copy the code below and paste it into the Code Editor. The code below will add "Knowledge Base Request: " to the subject line of all contact form submissions. You can edit that text in row 6 to be what you'd like to use.
<script> //add "Knowledge Base Request: " to subject line $('.hg-contact-form-container button[type=submit]').click(function(e){ e.preventDefault(); var subject = $('.hg-contact-form-container input[name=subject]').val(); $('.hg-contact-form-container input[name=subject]').val("Knowledge Base Request: " + subject); $('.hg-contact-us-form form').submit(); }); </script>
- Here's what a finished snippet might look like:
- Click the Create button.
- Copy the snippet's Merge Code Value. (In our example, it's {{snippet.contactFormSubject}}).
- Go to Settings > Style.
- Click the Custom HTML tab below the preview pane.
- Be sure the dropdown is set to Body.
- Paste your merge code anywhere into the Body.
- Save your changes.
Customize the subject line order
The code sample will put the text you have into the start of the contact form's subject. If you'd rather put it into the end, adjust the script so that subject + comes before the text string, for example:
<script>
//add "Knowledge Base Request: " to subject line
$('.hg-contact-form-container button[type=submit]').click(function(e){
e.preventDefault();
var subject = $('.hg-contact-form-container input[name=subject]').val();
$('.hg-contact-form-container input[name=subject]').val(subject + " - Knowledge Base Request");
$('.hg-contact-us-form form').submit();
});
</script>