Forum

Thread tagged as: Question

Personalise form's email response

I'm using a form with the response sent as email, via the Forms app. It's working correctly, both the input data and auto response are sent and received OK, but I want some functionality that I'm don't know how to achieve. The form template I'm using is based mainly on the example in Perch docs, like this (a couple of fields eliminated to save space):

<perch:form id="contact" method="post" app="perch_forms">

    <perch:content id="intro" type="textarea" label="Intro" size="xs" help="First lines of email message - use this to identify which page the submission is from." />

    <div class="form-field">
        <perch:label for="name">Name</perch:label>
        <perch:input type="text" id="name" required="true" label="Name" placeholder="your full name" />
        <perch:error for="name" type="required">Please add your name</perch:error>
    </div>

    <div class="form-field">
        <perch:label for="email">Email</perch:label>
        <perch:input type="email" id="email" required="true" label="Email" placeholder="your email address" />
        <perch:error for="email" type="required">Please add your email address</perch:error>
        <perch:error for="email" type="format">Please check your email address</perch:error>
    </div>

    <div class="form-field">
        <perch:input type="submit" id="submit" value="Send" />
    </div>

    <perch:success>
        <p class="success-message">Thank you, etc...</p>
    </perch:success>

</perch:form>

For the response email I've used "Submission from {name}" in the "Email subject line" in "Form options" and that's a useful way to identify the sender quickly, but I'd also like the editors to be able to enter the first lines of the email so that they can know exactly from which web page the response comes.

In this respect, I can only see in the resulting mail the generic text that's entered in "Form options" in the "Email introduction text" field. This method is too generic and doesn't allow for customising the emails when the template is used on different pages.

EDIT: You'll see from the code above that I've tried to use a perch:content field to get text into the email - I see now that that isn't going to do what I want. But my question still stands.

Really I just need a way to make the origin-page of the email identifiable. Can it be done?

Thanks

Peter Hammarling

Peter Hammarling 0 points

  • 4 years ago

You would need to populate this info into the form using a hidden field, then recall this info in the auto response. It can be done through passing variable into template.

Thanks for the pointer. I'm not sure I'm up to using variables yet but I'll certainly read up on them.

But one question: if the field is hidden, will Perch show it in the editors area (so that they can write a personalised message to themselves) ?

No, but if you gather the page info and pass this into the template you will have access to this info for use in the reply and response emails.

Drew McLellan

Drew McLellan 2638 points
Perch Support

By default, the submitting page is stored as the value page.

The above tips are really appreciated but they need a level of php knowledge that I don't have. Are these operations done within perch or would it need php code outside of perch? I don't know how I would fetch a 'page' value and then include it in the email.

If I ask for the code here is that above and beyond normal support? Are these things that are covered somewhere in the Perch documentation? I'm not averse to study but don't know what I should be looking at in this case.

Thanks

Hi,

The email sends the page path, so you could use this. If you add the following to the email template:

<p><perch:email id="perch_page_path" /></p>

It will output the path of the page the form submission came from as part of the email. Hope this helps, I am not entirely sure what you are aiming to do.

Mike Harrison said:

Hi,

The email sends the page path, so you could use this. If you add the following to the email template:

<p><perch:email id="perch_page_path" /></p>

It will output the path of the page the form submission came from as part of the email. Hope this helps, I am not entirely sure what you are aiming to do.

Or add {page} to the auto response in the form settings.

That didn't work when I tried it... though that would be the best approach if it did

Thanks Mike, Robert for the suggestions. I had tried entering {page} in various different fields of "Form options" but the value is not applied - in the email you just see the word {page}.

Mike, the form template will be in a master page and will be used by editors to create many different pages, and I want the email sent by the form to automatically contain something that easily identifies the sending page (page title would be good, though url would do). I know I can get the submitters name in the subject field but that's not sufficient for the way the emails need to be filed. In fact, in a wonderful world, the page title would be concatenated with the submitters name in the subject field.

I tried using

<p><perch:email id="perch_page_path" /></p>

in the form template but the page path is not sent to the email. I'm not using an email template, it seems like overkill for just 4 lines of info.

Ah ok, I think in that case down the rabbit hole we must go. This may not be the best approach but it is what I would do!

On the page you can set a variable to hold the page title, like this:

$pageTitle = perch_pages_title(true);
PerchSystem::set_var('page_title', $pageTitle);

This will make the page title available in your form template. You can then have a hidden input as part of the form that holds that value, like this:

<perch:input type="hidden" label="Page Title" id="pagetitle" value="<perch:content id="page_title"/>" />

This will then submit that along with the rest of the form, meaning it is available to use with curly brackets in the Perch form options. So you could do something like this:

Submission from {name} at {pagetitle}

Hope this helps

Mike Harrison said:

Ah ok, I think in that case down the rabbit hole we must go. This may not be the best approach but it is what I would do!

On the page you can set a variable to hold the page title, like this:

$pageTitle = perch_pages_title(true);
PerchSystem::set_var('page_title', $pageTitle);

This will make the page title available in your form template. You can then have a hidden input as part of the form that holds that value, like this:

<perch:input type="hidden" label="Page Title" id="pagetitle" value="<perch:content id="page_title"/>" />

This will then submit that along with the rest of the form, meaning it is available to use with curly brackets in the Perch form options. So you could do something like this:

Submission from {name} at {pagetitle}

Hope this helps

And here we are back to my original suggestion :)

Robert Ketter said: And here we are back to my original suggestion :)

Absolutely, I just thought it might be useful to the poster to see it worked through.

That works very well - exactly what I need and I really appreciate the step-by-step explanation. It doesn't in fact place the page title in the email subject line, which is what I was expecting, but seeing as you've put a perch:content tag in the hidden input field, a field is created in Perch admin and the editor can type there exactly the reference they want for the sending page. That appears in the email Subject line along with the submitters name.

I couldn't have created that code myself but it's a keeper for me, and I learnt from the exercise - thanks again to you both. Peter