0

I called contact form in my .phmtl page using this code:

<?php include ($block->getTemplateFile('Magento_Contact::form.phtml')) ?>

The problem is when I click on submit, there's no success message and we don't receive the mail by consequence.

PS:when I try mywebsite.com/contact it works correctly

6
  • when I try mywebsite.com/contact it works correctly Commented Jun 24, 2019 at 16:25
  • what do you mean exactly please! Commented Jun 24, 2019 at 16:53
  • Hey, check the form action @Nouarizineb Commented Jun 24, 2019 at 16:54
  • <form class="form contact" action="<?php echo $block->getFormAction(); ?>" id="contact-form" method="post" data-hasrequired="<?php /* @escapeNotVerified / echo __(' Required Fields') ?>" data-mage-init='{"validation":{}}'> Commented Jun 24, 2019 at 16:57
  • <?php echo $block->getFormAction();die; ?> and check before form Commented Jun 24, 2019 at 17:01

2 Answers 2

1

Please can U try this way to call form.phtml in your phtml file.

<?php echo $this->getLayout()->createBlock("Magento\Contact\Block\ContactForm")->setTemplate("Magento_Contact::form.phtml")->toHtml(); ?>

hope this helpful

2
  • Thank you! it works perfectly Commented Jun 25, 2019 at 9:03
  • Ok Thanks ..... Commented Jun 25, 2019 at 9:04
1

Use Below code direct into phtml file

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Contact::form.phtml")->toHtml(); ?>
2
  • Thank you! it works perfectly Commented Jun 25, 2019 at 9:04
  • Thank you @Nouarizineb .
    – Shorabh
    Commented Jun 25, 2019 at 9:42

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.