I am creating a Custom From 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 VendorModuleBlockAdminhtmlGridEdit;
/**
* Adminhtml Add New Row Form.
*/
class Form extends MagentoBackendBlockWidgetFormGeneric
{
/**
* @var MagentoStoreModelSystemStore
*/
protected $_systemStore;
/**
* @param MagentoBackendBlockTemplateContext $context
* @param MagentoFrameworkRegistry $registry
* @param MagentoFrameworkDataFormFactory $formFactory
* @param array $data
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoFrameworkDataFormFactory $formFactory,
MagentoCmsModelWysiwygConfig $wysiwygConfig,
VendorModuleModelStatus $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 dropdown in the form.