0
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php $buttonTitl = __('Get Quote'); ?>

<?php if ($_product->isSaleable()) :?>
<div class="box-tocart">
    <div class="fieldset">
        <?php if ($block->shouldRenderQuantity()) :?>
        <div class="field qty">
            <label class="label" for="qty"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
            <div class="control">
                <input type="number"
                       name="qty"
                       id="qty"
                       min="0"
                       value="<?= $block->getProductDefaultQty() * 1 ?>"
                       title="<?= $block->escapeHtmlAttr(__('Qty')) ?>"
                       class="input-text qty"
                       data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                       />
            </div>
        </div>
        <?php endif; ?>
        <div class="actions">
            <button type="submit"
                    title="<?= $block->escapeHtmlAttr($buttonTitle) ?>"
                    class="action primary tocart"
                    id="product-addtocart-button" disabled>
                <span><?= $block->escapeHtml($buttonTitle) ?></span>
            </button>
            <?= $block->getChildHtml('', true) ?>
            <button type="submit"
                    title="<?= $block->escapeHtmlAttr($buttonTitl) ?>"
                    class="action primary" 
                     disabled>
                <span><?= $block->escapeHtml($buttonTitl) ?></span>
            </button>
        </div>
    </div>
</div>
<a href="#" id="click-me">Get Quote</a>
<div id="popup-modal" style="display:none;">
    <form class="form" id="custom-form" method="post" autocomplete="off">
        <fieldset class="fieldset">
          <legend class="legend"><span><?php echo __('Personal Information') ?></span></legend><br>
           <div class="field required">
               <label for="email_address" class="label"><span><?php echo __('Email') ?></span></label>
                <div class="control">
                    <input type="email" name="email" id="email_address" value="" title="<?php echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
                </div>
            </div>
           <div class="field required">
               <label for="product_name" class="label"><span><?php echo __('Product Name') ?></span></label>
                <div class="control">
                    <input type="text" name="product_name" 
                    id="product_name" value="" title="<?php echo __('Product Name') ?>" class="input-text" disabled>
                </div>
            </div>

        </fieldset>
        <div class="actions-toolbar">
            <div class="primary">
                <button type="submit" class="action submit primary" title="<?php  echo __('Submit') ?>"><span><?php echo __('Submit') ?></span></button>
            </div>
        </div>
    </form>
</div>

<script>
    require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal'
    ],
    function(
        $,
        modal
    ) {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: true,
            title: 'Get Quote',
            buttons: [{
                text: $.mage.__('Continue'),
                class: '',
                click: function () {
                    this.closeModal();
                }
            }]
        };

        var popup = modal(options, $('#popup-modal'));
        $("#click-me").on('click',function(){ 
            $("#popup-modal").modal("openModal");
        });

    }
    );
</script>

<?php endif; ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {}
        }
    }
</script>
3
  • what exactly you want to get?? Jun 18 at 12:22
  • this is giving blank not giving value and I need the product name to be printed in my modal form
    – kks
    Jun 18 at 12:34
  • find below my updated answer Jun 18 at 12:48
0

$block->getProduct();

above function is loading from below file

vendor\magento\module-catalog\Block\Product\View.php

You can use value="<?= $_product->getName(); ?>"

hope this helps you :)

4
  • when I am placing its value in the value attribute of product name input then its not showing anything
    – kks
    Jun 18 at 12:56
  • could you please tell me what this $_product returns?
    – kks
    Jun 18 at 13:10
  • Thank you so much. You are really a great contributor in this community.
    – kks
    Jun 18 at 13:52
  • Happy to here this words..and this works for you..$_product return all attributes of product. You can print array or log array for get all attributes value. Jun 20 at 11:56
0

as you already have loaded the product :

$_product = $block->getProduct();

you can use $_product to get all the product attributes

e.g:

$_product->getName();
$_product->getSku();
$_product->getQty();

try to use echo $_product->getName(); in input value

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.