how can i move google captcha section before submit button in magento 2. i have add website key & secret key in magento google captcha. i have doesn't used any third party extension of google captcha. i have used google captcha only provided by magento. i have no idea how can i move to other position. please help me and thanks in advance.

enter image description here

1 Answer 1


There is a two solution to get this down to above the submit button. I will provide one solution for that.

first you need to create a module or theme to override the files.

  • you need to override the catalog_product_view.xml file as well as form.phtml file to make it possible.

override form.phtml file


here you need to add below code above the submit button.you need to add only getChildHtml() ?> code.

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

/** @var \Magento\Review\Block\Form $block */
<div class="block review-add">
    <div class="block-title"><strong><?= $block->escapeHtml(__('Write Your Own Review')) ?></strong></div>
<div class="block-content">
<?php if ($block->getAllowWriteReviewFlag()) : ?>
<form action="<?= $block->escapeUrl($block->getAction()) ?>" class="review-form" method="post" id="review-form" data-role="product-review-form" data-bind="scope: 'review-form'">
    <?= $block->getBlockHtml('formkey') ?>
    <?= $block->getChildHtml('form_fields_before') ?>
    <fieldset class="fieldset review-fieldset" data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
        <legend class="legend review-legend"><span><?= $block->escapeHtml(__("You're reviewing:")) ?></span><strong><?= $block->escapeHtml($block->getProductInfo()->getName()) ?></strong></legend><br />
        <?php if ($block->getRatings() && $block->getRatings()->getSize()) : ?>
        <span id="input-message-box"></span>
        <fieldset class="field required review-field-ratings">
            <legend class="label"><span><?= $block->escapeHtml(__('Your Rating')) ?></span></legend><br/>
            <div class="control">
                <div class="nested" id="product-review-table">
                    <?php foreach ($block->getRatings() as $_rating) : ?>
                        <div class="field choice review-field-rating">
                            <label class="label" id="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label"><span><?= $block->escapeHtml($_rating->getRatingCode()) ?></span></label>
                            <div class="control review-control-vote">
                            <?php $options = $_rating->getOptions();?>
                            <?php $iterator = 1; foreach ($options as $_option) : ?>
                                    name="ratings[<?= $block->escapeHtmlAttr($_rating->getId()) ?>]"
                                    id="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>"
                                    value="<?= $block->escapeHtmlAttr($_option->getId()) ?>"
                                    aria-labelledby="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label <?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>_label" />
                                    class="rating-<?= $block->escapeHtmlAttr($iterator) ?>"
                                    for="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>"
                                    title="<?= $block->escapeHtmlAttr(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?>"
                                    id="<?= $block->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $block->escapeHtmlAttr($_option->getValue()) ?>_label">
                                    <span><?= $block->escapeHtml(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?></span>
                                <?php $iterator++; ?>
                            <?php endforeach; ?>
                    <?php endforeach; ?>
                <input type="hidden" name="validate_rating" class="validate-rating" value="" />
    <?php endif ?>
        <div class="field review-field-nickname required">
            <label for="nickname_field" class="label"><span><?= $block->escapeHtml(__('Nickname')) ?></span></label>
            <div class="control">
                <input type="text" name="nickname" id="nickname_field" class="input-text" data-validate="{required:true}" data-bind="value: nickname()" />
        <div class="field review-field-summary required">
            <label for="summary_field" class="label"><span><?= $block->escapeHtml(__('Summary')) ?></span></label>
            <div class="control">
                <input type="text" name="title" id="summary_field" class="input-text" data-validate="{required:true}" data-bind="value: review().title" />
        <div class="field review-field-text required">
            <label for="review_field" class="label"><span><?= $block->escapeHtml(__('Review')) ?></span></label>
            <div class="control">
                <textarea name="detail" id="review_field" cols="5" rows="3" data-validate="{required:true}" data-bind="value: review().detail"></textarea>
    <?= $block->getChildHtml() ?>
    <div class="actions-toolbar review-form-actions">
        <div class="primary actions-primary">
            <button type="submit" class="action submit primary"><span><?= $block->escapeHtml(__('Submit Review')) ?></span></button>
<script type="text/x-magento-init">
    "[data-role=product-review-form]": {
        "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
    "#review-form": {
        "Magento_Review/js/error-placement": {},
        "Magento_Review/js/validate-review": {}
<?php else : ?>
    <div class="message info notlogged" id="review-form">
            <?= $block->escapeHtml(__('Only registered users can write reviews. Please <a href="%1">Sign in</a> or <a href="%2">create an account</a>', $block->getLoginLink(), $block->getRegisterUrl()), ['a']) ?>
<?php endif ?>

override catalog_product_view.xml file

<referenceBlock name="product.review.form">
<block class="MSP\ReCaptcha\Block\Frontend\ReCaptcha" name="msp-recaptcha_custom" after="-"
        <argument name="jsLayout" xsi:type="array">
            <item name="components" xsi:type="array">
                <item name="msp-recaptcha" xsi:type="array">
                    <item name="component" xsi:type="string">MSP_ReCaptcha/js/reCaptcha</item>
                    <item name="zone" xsi:type="string">review</item>

Also you need to add code to remove default recaptcha block to which is visible on top.

to remove add below code.

<referenceBlock name="msp-recaptcha" remove="true" />

Also you can use below solution to directly call your block with arguments in phtml.

how to call phtml inside phtml

I hope this will work for you.

Thank you.

  • hi @nirav thanks for reply, yes its working now. imgur.com/RPyirIK
    – Gaurav
    Apr 17, 2020 at 6:49
  • hi @nirav, i have update magento 2.4.3-p1, this code not work, can you help me ?
    – Gaurav
    Feb 2, 2022 at 10:10

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.