0

How to get custom table form table by form_id for custom table in magento 2.3.1?

try this but it's not working

custom table screen short:

enter image description here

Vendor\Module\Block\Form.php

 <?php

 namespace Vendor\Module\Block;

class Form extends \Magento\Framework\View\Element\Template
{
   protected $collectionFactory;

   public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Vendor\Module\Model\ResourceModel\ContactForms\CollectionFactory $collectionFactory
) {
    $this->collectionFactory = $collectionFactory;
    parent::__construct($context);
}

 public function getLoadForm($form_id)
  {
    return $this->collectionFactory->create()->load($form_id);
  }
}

customTemplate.phtml

<?php
   $formsCollection = $block->getLoadForm(form_id);

   echo $formsCollection->getTitle();
?>
9
  • You didn't pass form id in your phtml file. Dec 14, 2020 at 6:55
  • @RohanHapani i passed form id but it's Error filtering template: Notice: Undefined variable: form_id issue face Dec 14, 2020 at 6:59
  • It should be variable or direct int value. Dec 14, 2020 at 7:13
  • @RohanHapani How to fetch form data in phtml file please advance thank for help. Dec 14, 2020 at 7:17
  • Just try this : $form_id = 1; $formsCollection = $block->getLoadForm($form_id); in phtml file. Dec 14, 2020 at 7:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.