Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
7 
14 class Form extends \Magento\Backend\Block\Widget\Form\Generic
15 {
21  protected function _prepareForm()
22  {
24  $form = $this->_formFactory->create(
25  [
26  'data' => [
27  'id' => 'edit_form',
28  'action' => $this->getData('action'),
29  'method' => 'post'
30  ]
31  ]
32  );
33  $fieldset = $form->addFieldset('main_fieldset', ['legend' => __('New Encryption Key')]);
34  $fieldset->addField(
35  'enc_key_note',
36  'note',
37  ['text' => __('The encryption key is used to protect passwords and other sensitive data.')]
38  );
39  $fieldset->addField(
40  'generate_random',
41  'select',
42  [
43  'name' => 'generate_random',
44  'label' => __('Auto-generate a Key'),
45  'options' => [0 => __('No'), 1 => __('Yes')],
46  'onclick' => "var cryptKey = jQuery('#crypt_key'); var cryptKeyBlock = cryptKey.parent().parent(); ".
47  "cryptKey.prop('disabled', this.value === '1'); " .
48  "if (cryptKey.prop('disabled')) { cryptKeyBlock.hide() } " .
49  "else { cryptKeyBlock.show() }",
50  'note' => __('The generated key will be displayed after changing.')
51  ]
52  );
53  $fieldset->addField(
54  'crypt_key',
55  'text',
56  ['name' => 'crypt_key', 'label' => __('New Key'), 'style' => 'width:32em;', 'maxlength' => 32]
57  );
58  $form->setUseContainer(true);
59  if ($data = $this->getFormData()) {
60  $form->addValues($data);
61  }
62  $this->setForm($form);
63  return parent::_prepareForm();
64  }
65 }
getData($key='', $index=null)
Definition: DataObject.php:119
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112
__()
Definition: __.php:13