{layout='layouts/_contact-layout'}

{!--
	404 Redirect
	============
	This is a single entry channel page, it only needs a second segment when the form has been successfully submitted. So we use the following code to make sure the page sends a 404 if someone types in an incorrect URL in the browser address bar. i.e. http://example.com/page/nothing
--}
{if segment_2 AND segment_2 != 'thanks'}
	{redirect='404'}
{/if}

{!-- page vars (prefix p_) --}
{preload_replace:p_title='contact {site_name}'}
{preload_replace:p_description='contact {site_name}'}
{preload_replace:p_url='contact'}
{!-- channel vars (prefix ch_) --}
{preload_replace:ch='contact'}
{preload_replace:ch_disable='categories|category_fields|member_data|pagination'}
{!-- layout vars, channel/page related --}
{layout:set name='ch' value='{ch}'}
{layout:set name='p_url' value='{p_url}'}
{layout:set name='p_title' value='{p_title}'}
{layout:set name='ch_disable' value='{ch_disable}'}

		{exp:channel:entries channel='{ch}' disable='{ch_disable}' limit='1'}
			{!-- layout vars, dynamic, not output --}
			{layout:set name='title' value='{seo_title}{gv_sep}'}
			{layout:set name='description' value='{seo_desc}'}
			{!-- OpenGraph meta output --}
			{layout:set name='og_title' value='{seo_title}'}
			{layout:set name='og_url'}{path='{p_url}'}{/layout:set}
			{layout:set name='og_description' value='{seo_desc}'}
			{!-- /layout vars, dynamic, not output --}

			{!-- content output --}
			<h1>{title} <span class="required">Required Fields &#10033;</span></h1>
			{!-- page_content is a textarea with HTML output we don't need to wrap this tag with HTML as that is already included in it's output. --}
			{page_content}
			{!-- /content output --}

			{!--
				no results redirect
				===================
				If the page doesn't exist, we redirect to 404.
			--}
			{if no_results}
				{redirect='404'}
			{/if}
		{/exp:channel:entries}

		<div class="alert issue hide"></div>
		{!-- only show this thank you message if segment_2 is thanks --}
		{if segment_2 == 'thanks'}
			<div class="alert success">
				<h3>email sent</h3>
				<p>Thanks, your email was sent, we'll respond in 48 hours or less.</p>
				<a class="close" href="{path='{p_url}'}">&#10005; Close</a>
			</div>
		{/if}
		{!-- email contact form --}

		{exp:email:contact_form form_class='contact-form' return='{site_url}index.php/{p_url}/thanks' redirect='0'}
			<fieldset class="row">
				<section class="w-4 instruct">
					<label>Name</label>
					<em>What do you want to be called?</em>
				</section>
				<section class="w-12 field">
					<input name="name" type="text" value="{member_name}">
				</section>
			</fieldset>
			<fieldset class="row">
				<section class="w-4 instruct">
					<label>Email <span class="required" title="required field">&#10033;</span></label>
					<em>How do we contact you?</em>
				</section>
				<section class="w-12 field">
					<input class="required" name="from" type="text" value="{member_email}">
				</section>
			</fieldset>
			<fieldset class="row">
				<section class="w-4 instruct">
					<label>Subject</label>
					<em>What did you want to discuss?</em>
				</section>
				<section class="w-12 field">
					<input name="subject" type="text" value="">
				</section>
			</fieldset>
			<fieldset class="row">
				<section class="w-4 instruct">
					<label>Message <span class="required" title="required field">&#10033;</span></label>
					<em>Please keep it kind, brief and courteous.</em>
				</section>
				<section class="w-12 field">
					<textarea class="required" name="message" cols="" rows=""></textarea>
				</section>
			</fieldset>
			<fieldset class="ctrls">
				<input class="btn" type="submit" value="Send e-mail">
			</fieldset>
		{/exp:email:contact_form}
