I set button in form popup in product-detail page in addtocart.phtml in my custom module.

But form submit button is not working and data not passed to controller so not saved in the database

Here is my code.

addtocart.phtml file:

 <div id="popup-modal" style="display:none;">    
  <form method="post" id="quote_form" action=<?php echo $block->getUrl('quote/index/addquotedata');?>>
  <input type="text" name="name" id="name" value="<?php echo $_product->getName();?>">
  <input type="number" name="quote_qty" id="quote_qty">

  <input type="text" name="quote_price" id="quote_price">
  <input type="text" name="quote_desc" id="quote_desc">

  <!-- <button type="submit" name="submit" id="submit">submit</button> -->

        function($,modal) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                title: 'Product Question',
                closeText: 'Close',
                buttons: [{
                    text: $.mage.__('Submit'),
                    class: '',
                    click: function (data) {

                            url: "<?php  echo $block->getBaseUrl().'quote/index/addquotedata/';?>",
                            type: 'POST',
                            data : {product_name :name,quote_qty:quote_qty,quote_price:quote_price,quote_desc:quote_desc}                    

                        // this.closeModal();


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

And this is my Controller file

    use Magento\Framework\Controller\ResultFactory;
    use Magento\Framework\App\Action\Action;
    use Magento\Framework\App\Action\Context;
    use Infy\Quotesystem\Model\ResourceModel\Post\CollectionFactory;

    class Addquotedata extends Action {

        protected $request;
        protected $collectionFactory;
        protected $_pageFactory;
        protected $_resulFactory;
        protected $customerResourceFactory;

        public function __construct(Context $context, CollectionFactory $collectionFactory,
            \Magento\Framework\Controller\ResultFactory $resulFactory,
            \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
            \Magento\Framework\View\Result\PageFactory $pageFactory) {

            $this->collectionFactory = $collectionFactory;
            $this->_pageFactory = $pageFactory;
            $this->_resultFactory = $resulFactory;
            $this->customerRepository = $customerRepository;

        public function execute() {

            $pageFactory = $this->_pageFactory->create();

            $qty = $this->getRequest()->getParam('quote_qty',null);        
            $price = $this->getRequest()->getParam('quote_price',null); 
            $desc = $this->getRequest()->getParam('quote_desc',null);
            $name = $this->getRequest()->getParam('product_name',null);
            $std = $this->_objectManager->create('Infy\Quotesystem\Model\ResourceModel\Post');

             echo "Inserted Data";

It gives error in console: Uncaught TypeError:

Illegal invocation

at add (jquery.js:10073)

at buildParams (jquery.js:10061)

at buildParams (jquery.js:10055)

at buildParams (jquery.js:10055)

at Function.jQuery.param (jquery.js:10095)

at Function.ajax (jquery.js:9612)

at $.<computed>.<computed>.click (test.html:490)

at HTMLButtonElement.dispatch (jquery.js:5226)

at HTMLButtonElement.elemData.handle (jquery.js:4878)
  • please check ajax response or system.log . If any error return then please post here. – Rohan Hapani Aug 26 '19 at 11:29
  • Check my updated question – moni patel Aug 26 '19 at 11:31
  • Please add in your question and also post system.log – Rohan Hapani Aug 26 '19 at 11:32
  • There is no system.log – moni patel Aug 26 '19 at 11:43

Your Answer

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

Browse other questions tagged or ask your own question.