0

I use a contactformular in my magento shop https://agoshop.at/kontakt The problem is that I will get very day up to 4 an more dummy contact informations. I think I will need there a captcha in this form to check if the user is a human. I will check my backend and find a site contact with the following content:

<p><strong>{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}</strong></p>

I find a form.phtml file in the folder \vendor\magento\module-contact\view\frontend\templates with the following content:

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

/** @var \Magento\Contact\Block\ContactForm $block */
?>
<form class="form contact"
      action="<?= $block->escapeUrl($block->getFormAction()) ?>"
      id="contact-form"
      method="post"
      data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>"
      data-mage-init='{"validation":{}}'>
    <fieldset class="fieldset">
        <legend class="legend"><span><?= $block->escapeHtml(__('Write Us')) ?></span></legend><br />
        <div class="field note no-label"><?= $block->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><?= $block->escapeHtml(__('Name')) ?></span></label>
            <div class="control">
                <input name="name" id="name" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="<?= $block->escapeHtmlAttr($this->helper(\Magento\Contact\Helper\Data::class)->getPostValue('name') ?: $this->helper(\Magento\Contact\Helper\Data::class)->getUserName()) ?>" class="input-text" type="text" data-validate="{required:true}"/>
            </div>
        </div>
        <div class="field email required">
            <label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
            <div class="control">
                <input name="email" id="email" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value="<?= $block->escapeHtmlAttr($this->helper(\Magento\Contact\Helper\Data::class)->getPostValue('email') ?: $this->helper(\Magento\Contact\Helper\Data::class)->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><?= $block->escapeHtml(__('Phone Number')) ?></span></label>
            <div class="control">
                <input name="telephone" id="telephone" title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value="<?= $block->escapeHtmlAttr($this->helper(\Magento\Contact\Helper\Data::class)->getPostValue('telephone')) ?>" class="input-text" type="text" />
            </div>
        </div>
        <div class="field comment required">
            <label class="label" for="comment"><span><?= $block->escapeHtml(__('Wie können wir Ihnen behilflich sein?')) ?></span></label>
            <div class="control">
                <textarea name="comment" id="comment" title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>" class="input-text" cols="5" rows="3" data-validate="{required:true}"><?= $block->escapeHtml($this->helper(\Magento\Contact\Helper\Data::class)->getPostValue('comment')) ?></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="<?= $block->escapeHtmlAttr(__('Submit')) ?>" class="action submit primary">
                <span><?= $block->escapeHtml(__('Submit')) ?></span>
            </button>
        </div>
    </div>
</form>

So I think this is the correct file but how can I add a captcha? Hope someone can help me there. kindly regards

8
  • Is using agoshop.at/contact instead and removing that /kontakt page (and redirect /kontakt to /contact if needed) an option? Commented Jan 9, 2022 at 1:19
  • Thanks for this tip. I didn't notice that it will forward to contact. I have changed it. It works now fine. kindly regards
    – haiflosse
    Commented Jan 9, 2022 at 18:49
  • I noticed now an other small problem. The text infront of the textbox for the captcha is not complete: Here a picture of the problem: dropbox.com/s/ytke7524qlnu9tl/contact_captcha.png?dl=0 Hope someone has still a solution. KIndly regards
    – haiflosse
    Commented Jan 9, 2022 at 19:46
  • You probably want to check out this duplicate in regard to the captcha in cms pages: magento.stackexchange.com/a/232487/34469 In regard to your label-issue: You've got some nasty width definition on .fieldset > .field:not(.choice) > .label and .fieldset > .field:not(.choice) > .control (width is fixed to 25.8% resp 74.2% and floating) hence your overlapping Commented Jan 10, 2022 at 7:40
  • Thanks for your answer. Can you informe me in which file I can find the settings of the wrong width. Also I cannot find it in any menu in the magento backend. kindly regards again.
    – haiflosse
    Commented Jan 10, 2022 at 17:30

1 Answer 1

0

I have find now an instruction to activate captcha also for a contact form. https://ccbill.com/kb/magento-contact-captcha When I want to send a new message via the contactform and after I press the button I will get a message to insert a captcha. I don't see the captcha before. So I want ask if it is possible to see the captcha already when I open the contact formular. kindly regards for any answer

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.