x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Allow unique contact email for each weblog entry

I recently came upon the necessity to specify a different email address per weblog entry AND use this email address in the EE Contact form. The problem is you cannot include the EE contact form in a weblog entry. There is a solution however. You can pass a variable to an embedded template which in the end assisted me to achieve my solution. Here is how I did this:

Note: In the { embed part you will need to remove the space when copying and pasting.

{if email_contact > " "}{ embed="templategroup/contact_form" email_me="{email_contact}" return_me="{url_title}"}{/if}

The short name for my weblog field in this case is “email_contact”. I specified the variable “email_me” to pass along the data from the variable {email_contact}. I also specified another variable to be passed in the embed titled “return_me” which I just simple specified with {url_title}. I wrapped it in a conditional so that it will only grab this embedded template if the field is populated with an email address.

Then I created my new template which would be used for the embed titled “contact_form”.

{exp:email:contact_form user_recipients="false" recipients="{embed:email_me}" charset="utf-8" return="http://www.domain.com/index.php/templategroup/templatename/{embed:return_me}"}
<h1>Contact this organization:</h1>
<
p><label for="from">Your Email:</label><br />
<
input type="text" id="from" name="from" size="40" maxlength="35" value="{member_email}" /></p>
<
p><label for="subject">Subject:</label><br />
<
input type="text" id="subject" name="subject" size="40" value="Contact Form" /></p>
<
p><label for="message">Message:</label><br />
<
textarea id="message" name="message" rows="18" cols="40">Support Email from: {member_name}
Sent at
: {current_time format="%Y %m %d"}</textarea></p>
<
p><input name="submit" type='submit' value='Submit Form' /></p>
{/exp:email:contact_form}

The majority of this is straight from the EE support page example but notice the {exp:email:contact_form} tag. I specified the variable being passed to it as {embed:email_me} which is replaced by the email entered in the weblog field and {embed:return_me} which get’s replaced with the URL title. You have to create a URL for the return address otherwise once the contact form is used the visitor will be directed to the embedded page and not the original page of which the form was embedded in.

Related information:
Original Forum posting
Embed Variables for the Embedded Template
Contact Form usage at EEdocs

Category:Email Category:Entries Category:Templates

Categories: