1

I'm trying to develop my contacts page but I'm receiving some unusual behaviour.

I've created the Contacts Page mydomain.com/contact and the contact form gets loaded via:

{{block class="Magento\Contact\Block\ContactForm" 
name="contactForm" template="Magento_Contact::form.phtml"}}

Here is form.html from my theme:

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<div class="contact-us-page">

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('google-map')->toHtml(); ?>

    <div class="row form-contact">
<div class="col-lg-4 col-md-4">
<div class="contact-info">

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('contact-store-info')->toHtml(); ?>

</div>
</div>
<div class="col-lg-8 col-md-8">
    <form class="form contact"
          action="<?php /* @escapeNotVerified */
          echo $block->getFormAction(); ?>"
          id="contact-form"
          method="post"
          data-hasrequired="<?php /* @escapeNotVerified */
          echo __('* Required Fields') ?>"
          data-mage-init='{"validation":{}}'>
        <fieldset class="fieldset">
            <div class="title-bonus-page">
                <h2><?php /* @escapeNotVerified */
                    echo __('Send your comments') ?></h2>
            </div>
            <div class="left-input">
                <div class="field name required">
                    <div class="control">
                        <input placeholder="<?php echo __('Your Name*') ?>" name="name" id="name" title="<?php /* @escapeNotVerified */
                        echo __('Name') ?>" value="<?php echo $block->escapeHtml($this->helper('Magento\Contact\Helper\Data')->getUserName()) ?>" class="input-text" type="text" data-validate="{required:true}"/>
                    </div>
                </div>
                <div class="field email required">
                    <div class="control">
                        <input placeholder="<?php echo __('Your Email*') ?>" name="email" id="email" title="<?php /* @escapeNotVerified */
                        echo __('Email') ?>" value="<?php echo $block->escapeHtml($this->helper('Magento\Contact\Helper\Data')->getUserEmail()) ?>" class="input-text" type="email" data-validate="{required:true, 'validate-email':true}"/>
                    </div>
                </div>
                <div class="field telephone">
                    <div class="control">
                        <input placeholder="<?php echo __('Your Phone') ?>" name="telephone" id="telephone" title="<?php /* @escapeNotVerified */
                        echo __('Phone Number') ?>" value="" class="input-text" type="text"/>
                    </div>
                </div>
            </div>
            <div class="field comment required">
                <div class="control">
                    <textarea placeholder="<?php echo __('Your Message*') ?>" name="comment" id="comment" title="<?php /* @escapeNotVerified */
                    echo __('What’s on your mind?') ?>" class="input-text" cols="5" rows="3" data-validate="{required:true}"></textarea>
                </div>
            </div>
            <?php echo $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="<?php /* @escapeNotVerified */
                echo __('Send Message') ?>" class="action submit primary">
                    <span><?php /* @escapeNotVerified */
                        echo __('Send Message') ?></span>
                </button>
            </div>
        </div>
    </form>
</div>
</div>
</div>

This works great and displays everything correctly (No Captcha) however when I hit "Send Message" The Page reloads and asks for Captcha. It also changes the url. The new url has an /index/ on the end of it mydomain.com/contact/index/.

I'm not sure why its doing this. How can I get the page to load correctly with Captcha on mydomain.com/contact

1

Try this,

index is nothing but an action name by default you could load the contact us page by

www.domain.com/contact/index and it does return the same page. So if you do not want that index to append in the sense you can remove it in below file.

vendor/magento/module-contact/Controller/Index/Post.php

replace this

return $this->resultRedirectFactory->create()->setPath('contact/index');

with this

return $this->resultRedirectFactory->create()->setPath('contact/');

Of course you have override the post controller in you custom module.

Then if you want to configure the captcha to you form in the sense you can configure it in admin by

Stores->Configuration->Customer->Customer Configuration->Enable Captcha -> You can select and save your form.

Hope this information helps you :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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