I am creating a custom fom in admin and want to load the custom select option in the form as a select field options.
Below is my code :
app/code/Vendor/Module/Block/Adminhtml/Grid/Edit/Form.php
<?php
namespace Vendor\Module\Block\Adminhtml\Grid\Edit;
/**
* Adminhtml Add New Row Form.
*/
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
/**
* @var \Magento\Store\Model\System\Store
*/
protected $_systemStore;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
\Vendor\Module\Model\Status $options,
array $data = []
)
{
$this->_options = $options;
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* Prepare form.
*
* @return $this
*/
protected function _prepareForm()
{
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
$model = $this->_coreRegistry->registry('row_data');
$form = $this->_formFactory->create(
['data' => [
'id' => 'edit_form',
'enctype' => 'multipart/form-data',
'action' => $this->getData('action'),
'method' => 'post'
]
]
);
$form->setHtmlIdPrefix('question_');
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('NAME'),
'id' => 'name',
'title' => __('NAME'),
'class' => 'required-entry',
'required' => true,
]
);
$fieldset->addField(
'email',
'text',
[
'name' => 'email',
'label' => __('Email'),
'id' => 'email',
'title' => __('Email'),
'class' => 'required-entry',
'required' => true,
]
);
$fieldset->addField('is_answered', 'select',
[
'name' => 'is_answered',
'label' => __('Status'),
'options' => ['1' => __('Pending By Seller'), '0' => __('Pending By Admin')],
'required' => true,
]);
$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
I want to load custom data(email) entries from custom table in the email field as a drop-down in the form.