1

This is a follow-up to an earlier question from 2014: P&T Contact Form plugin: How can I copy “name” and “email address” in the body of the mail? ... it seems that Craft (and the plugin) has gone through significant updates since that question was answered.

How would I include fromName and fromEmail into the body of the message?

I read about events in the documentation, but it doesn't say where they go. Do I put those into the craft>config>contactform.php file? How would I setup an event to handle that inclusion?

2
  • What context do you wan to include it? Do you want to say "Message from Jeff his email is "[email protected]" and then show the contents of the body? Or do you want to inject the to/email within the body of the message? For example, if Jeff had a message of "Hey i like your site [Jeff] [[email protected]] have a great day". Who would get this email? The admin or the user as a confirmation email?
    – Damon
    Commented Oct 15, 2017 at 14:45
  • I’m trying to use it as a basic signup form. I edited the config file to allow for recipients to be controlled from the template as an entry... I would be okay if just fromName and fromEmail passed through onto the message body Commented Oct 15, 2017 at 16:16

1 Answer 1

2

I figured it out by duplicating the field...

<input id="fromName" type="text" name="fromName" 
value="{% if message is defined %}{{ message.fromName }}{% endif %}">
{{ message is defined and message ? errorList(message.getErrors('fromName')) }}
<input type="hidden" id="fullName" name="message[Full Name]" class="fullName">

Then duplicating the single entry to the hidden with some Javascript...

    $('#fromName').bind('keypress keyup blur', function() {
      $('#fullName').val($(this).val());
    });

It parses through to the email message as:

Full Name: First Last

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.