0
<?php
/**

/** @var $block \Magento\Catalog\Block\Product\View */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php $isSaleable = $_product->isSaleable();?>
<?php if($_product->getFinalPrice() > 0){ ?>
<div class="box-tocart">
    <div class="fieldset">
        <?php if ($block->shouldRenderQuantity()): ?>
        <div class="field qty">
            <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
            <div class="control">
                <input type="number"
                       name="qty"
                       id="qty"
                       value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
                       title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                       class="input-text qty"
                       data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                       />
            </div>
        </div>
        <?php endif; ?>
        <div class="actions">
            <button type="submit"
                    title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
                    class="action primary tocart"
                    id="product-addtocart-button" <?php echo ($_product->isVirtual() && $isSaleable)?'':'disabled'; ;?>>
                <span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
            </button>
            <?php if($isSaleable):?>
                <?= $block->getChildHtml('', true) ?>
            <?php endif;?>
        </div>
    </div>
</div>
<?php if ($block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/product/view/validation": {
                "radioCheckboxClosest": ".nested"
            }
        }
    }
</script>
<?php else : ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {}
        }
    }
</script>
<?php endif; ?>
<?php } else{ ?>

<?php 
$erHelper = $this->helper('Eaglerocket\Customquote\Helper\Data');
$questions = $erHelper->getQuestions();
 ?>
  <div class="box-tocart">
      <div class="fieldset">
        <div class="actions">
          <button type="button" class="action primary tocart btn btn-primary btn-lg" id="popupButton" data-toggle="modal" data-target="#myModal"><?php echo __('Quote')?></button>
        </div>
      </div>
  </div>
  <!-- Modal $question->getQuestion()-->
  <div class="modal fade" id="myModal" role="dialog" style="display:none;">
    <div class="modal-dialog">
      <!-- Modal content data-validate="{required:true}" aria-required="true"-->
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title"><?php echo __('Get Quote')?></h4>
        </div>
        <div class="modal-body">
          <form  method="post" action="<?php echo $block->getBaseUrl() ?>" >
            <fieldset class="fieldset">
              <?php foreach ($questions as $question) { ?>
                <div class="field comment required">
                    <div class="control">
                        <textarea name="comment"  title="<?php echo $question->getQuestion() ?>" placeholder="<?php echo $question->getQuestion() ?>" class="input-text" cols="5" rows="3"></textarea>
                    </div>
                </div>
              <?php } ?>
              <div class="field comment required">
                    <div class="control">
                        <textarea name="email" id="email" title="<?php echo ('Email') ?>" 
                            placeholder="('customquote/index/index') " 
                            class="input-text" cols="5" rows="3" data-validate="{required:true}" aria-required="true">
                            </textarea>
                    </div>
                </div>
            </fieldset>
<!--             <div class="actions-toolbar">-->  
    <div>
             <div class="primary">
<!--                   <input type="hidden" name="hideit" id="hideit" value="">
 -->                  <button type="submit" title="Submit">
                      <span>Submit</span>
                  </button>
              </div>
            </div>

          </form>
        </div>
      </div>
    </div>
  </div>
<script>
 
require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                 
               
                buttons: [{
                    text: $.mage.__('Continue'),
                    class: 'mymodal1',
                    click: function () {
                        this.closeModal();
                    }
                }]
             };
            var popup = modal(options, $('#myModal'));
            $("#popupButton").on('click',function(){
                $("#myModal").modal("openModal");
            });
        
});

  </script>
<?php } ?>
0

use this first you have model popup and below that you have your ajax call

    <div class="callfor-popup">
       <h2>Simple Modal</h2>
    </div>
    <script>
       require(['jquery','Magento_Ui/js/modal/modal'],
        function ($,modal) {
               var modaloption = {
                   type: 'popup',
                   modalClass: 'modal-popup',
                   responsive: true,
                   innerScroll: true,
                   clickableOverlay: true,
                   title: 'Simple Modal'
               };
               modal(modaloption, $('.callfor-popup'));
               $('.callfor-popup').modal('openModal');
           }

//change class name to model popup "ok" button class name
           $(".yourButtonClass").on('click', function(event){
                var base_url = window.location.origin;
                var customurl = base_url + "/sampleorder/sampleorder/search";
                $.ajax({
                    url: customurl,
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        customdata1: 'test1',
                        customdata2: 'test2',
                    },
                complete: function(response) {             
                   // country = response.responseJSON.default_country;
                   // state = response.responseJSON.state;         
                   // console.log(state+' '+country);   
                    },
                    error: function (xhr, status, errorThrown) {
                        console.log('Error happens. Try again.');
                    }
                });
            });
       );
    </script>
            

upvote if helps

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.