Skip to content

Instantly share code, notes, and snippets.

@mrtuvn
Last active August 2, 2020 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtuvn/7b275f2f50ad7d8703ccb0d69b910656 to your computer and use it in GitHub Desktop.
Save mrtuvn/7b275f2f50ad7d8703ccb0d69b910656 to your computer and use it in GitHub Desktop.
contact form template magento 2 follow standard
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// phpcs:disable Magento2.Templates.ThisInTemplate
// phpcs:disable Generic.Files.LineLength.TooLong
/**
* @var \Magento\Contact\Block\ContactForm $block
* @var \Magento\Framework\Escaper $escaper
* @var \Magento\Contact\ViewModel\UserDataProvider $viewModel
*/
$escaper = isset($escaper) ? $escaper : $block;
$viewModel = $block->getViewModel();
?>
<form class="form contact"
action="<?= $escaper->escapeUrl($block->getFormAction()) ?>"
id="contact-form"
method="post"
data-hasrequired="<?= $escaper->escapeHtmlAttr(__('* Required Fields')) ?>"
data-mage-init='{"validation":{}}'>
<fieldset class="fieldset">
<legend class="legend"><span><?= $escaper->escapeHtml(__('Write Us')) ?></span></legend><br />
<div class="field note no-label">
<?= $escaper->escapeHtml(__('Jot us a note and we’ll get back to you as quickly as possible.')) ?>
</div>
<div class="field name required">
<label class="label" for="name"><span><?= $escaper->escapeHtml(__('Name')) ?></span></label>
<div class="control">
<input name="name"
id="name"
title="<?= $escaper->escapeHtmlAttr(__('Name')) ?>"
value="<?= $escaper->escapeHtmlAttr($viewModel->getUserName()) ?>"
class="input-text"
type="text"
data-validate="{required:true}"/>
</div>
</div>
<div class="field email required">
<label class="label" for="email"><span><?= $escaper->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="email"
id="email"
title="<?= $escaper->escapeHtmlAttr(__('Email')) ?>"
value="<?= $escaper->escapeHtmlAttr($viewModel->getUserEmail()) ?>"
class="input-text"
type="email"
data-validate="{required:true, 'validate-email':true}"/>
</div>
</div>
<div class="field telephone">
<label class="label" for="telephone"><span><?= $escaper->escapeHtml(__('Phone Number')) ?></span></label>
<div class="control">
<input name="telephone"
id="telephone"
title="<?= $escaper->escapeHtmlAttr(__('Phone Number')) ?>"
value="<?= $escaper->escapeHtmlAttr($viewModel->getUserTelephone()) ?>"
class="input-text"
type="tel" />
</div>
</div>
<div class="field comment required">
<label class="label" for="comment">
<span><?= $escaper->escapeHtml(__('What’s on your mind?')) ?></span>
</label>
<div class="control">
<textarea name="comment"
id="comment"
title="<?= $escaper->escapeHtmlAttr(__('What’s on your mind?')) ?>"
class="input-text"
cols="5"
rows="3"
data-validate="{required:true}"><?= $escaper->escapeHtml($viewModel->getUserComment()) ?>
</textarea>
</div>
</div>
<?= $block->getChildHtml('form.additional.info') ?>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" name="hideit" id="hideit" value="" />
<button type="submit" title="<?= $escaper->escapeHtmlAttr(__('Submit')) ?>" class="action submit primary">
<span><?= $escaper->escapeHtml(__('Submit')) ?></span>
</button>
</div>
</div>
</form>
<script type="text/x-magento-init">
{
"*": {
"Magento_Customer/js/block-submit-on-send": {
"formId": "contact-form"
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment