Scaffolds the fields required for editing the record

@return Form
356670
public function Form()
    {
        if ($this->currentRecord) {
            $fields = $this->currentRecord->getFrontEndFields();
            $required = $this->currentRecord->getRequiredFields();
        } else {
            $fields = singleton($this->recordType)->getFrontEndFields();
            $required = singleton($this->recordType)->getFrontEndFields();
        }

        $fields->push(new HiddenField('ID'));
        $form = new Form($this, __function__, $fields, new FieldList(new FormAction('doSave', 'Save')), $required);
        if ($this->currentRecord) {
            $form->loadDataFrom($this->currentRecord);
        }
        return $form;
    }
259434
protected function createComponentEditForm(): Form
	{
		$form = $this->formFactory->create();

		$form->addText('name', 'default.name')
			->setRequired();

		if ($this->editConst) {
			$form->addText('const', 'webManager.web.content.const')
				->setRequired();

			$form->addSelectUntranslated('locale', 'webManager.web.pages.locale')
				->setItems($this->localeService->allowed);
		}

		$form->addText('title', 'webManager.web.content.contentTitle')
			->addRule(Form::MAX_LENGTH, null, 150)
			->setRequired(false);

		$form->addTextArea('keywords', 'webManager.web.content.keywords');

		$form->addImageUpload('image', 'webManager.web.content.photo', 'webManager.web.content.photoDelete')
			->setNamespace('content')
			->setPreview('300x100');

		$form->addColor('background', 'webManager.web.content.background');

		$form->addTextArea('description', 'webManager.web.content.description');

		$form->addTextEditor('content', 'webManager.web.content.content');

		$form->addSubmit('save', 'form.save');

		$form->addLink('back', 'form.back', $this->getBacklink());

		$form->onSuccess[] = [$this, 'editFormSucceeded'];

		return $form;
	}
1289001
protected function _FromForm() {
      $Form = new Gdn_Form();
      $Px = $this->Prefix;

      $Types = (array)$Form->GetFormValue($Px.'Type', array());
      $PermissionFields = (array)$Form->GetFormValue($Px.'PermissionField', array());
      $RoleFields = (array)$Form->GetFormValue($Px.'RoleField', array());
      $Fields = (array)$Form->GetFormValue($Px.'Field', array());
      $Expressions = (array)$Form->GetFormValue($Px.'Expr', array());

      $Conditions = array();
      for ($i = 0; $i < count($Types) - 1; $i++) { // last condition always template row.

         $Condition = array($Types[$i]);
         switch ($Types[$i]) {
            case Gdn_Condition::PERMISSION:
               $Condition[1] = GetValue($i, $PermissionFields, '');
               break;
            case Gdn_Condition::REQUEST:
               $Condition[1] = GetValue($i, $Fields, '');
               $Condition[2] = GetValue($i, $Expressions, '');
               break;
            case Gdn_Condition::ROLE:
               $Condition[1] = GetValue($i, $RoleFields);
               break;
            case '':
               $Condition[1] = '';
               break;
            default:
               continue;
         }
         $Conditions[] = $Condition;
      }
      return $Conditions;
   }
1217804
public function bulkEditForm()
    {
        $crumbs = $this->Breadcrumbs();
        if ($crumbs && $crumbs->count() >= 2) {
            $one_level_up = $crumbs->offsetGet($crumbs->count() - 2);
        }

        $actions = new FieldList();

        $actions->push(
            FormAction::create('doSave', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_BTN_LABEL', 'Save all'))
                ->setAttribute('id', 'bulkEditingSaveBtn')
                ->addExtraClass('btn btn-success')
                ->setAttribute('data-icon', 'accept')
                ->setUseButtonTag(true)
        );

        $actions->push(
            FormAction::create('Cancel', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.CANCEL_BTN_LABEL', 'Cancel'))
                ->setAttribute('id', 'bulkEditingUpdateCancelBtn')
                ->addExtraClass('btn btn-danger cms-panel-link')
                ->setAttribute('data-icon', 'decline')
                ->setAttribute('href', $one_level_up->Link)
                ->setUseButtonTag(true)
                ->setAttribute('src', '')//changes type to image so isn't hooked by default actions handlers
        );

        $recordList = $this->getRecordIDList();
        $recordsFieldList = new FieldList();
        $config = $this->component->getConfig();

        $editingCount = count($recordList);
        $modelClass = $this->gridField->getModelClass();
        $singleton = singleton($modelClass);
        $titleModelClass = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());

        //some cosmetics
        $headerText = _t(
            'GRIDFIELD_BULKMANAGER_EDIT_HANDLER.HEADER_TEXT',
            'Editing {count} {class}',
            array(
                'count' => $editingCount,
                'class' => $titleModelClass,
            )
        );
        $header = LiteralField::create(
            'bulkEditHeader',
            '<h1 id="bulkEditHeader">'.$headerText.'</h1>'
        );
        $recordsFieldList->push($header);

        $toggle = LiteralField::create(
            'bulkEditToggle',
            '<span id="bulkEditToggle">' . _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.TOGGLE_ALL_LINK', 'Show/Hide all') . '</span>'
        );
        $recordsFieldList->push($toggle);

        //fetch fields for each record and push to fieldList
        foreach ($recordList as $id) {
            $record = DataObject::get_by_id($modelClass, $id);
            $recordEditingFields = $this->getRecordEditingFields($record);

            $toggleField = ToggleCompositeField::create(
                'RecordFields_' . $id,
                $record->getTitle(),
                $recordEditingFields
            )
            ->setHeadingLevel(4)
            ->setAttribute('data-id', $id)
            ->addExtraClass('bulkEditingFieldHolder');

            $recordsFieldList->push($toggleField);
        }

        $bulkEditForm = Form::create(
            $this,
            'recordEditForm', //recordEditForm name is here to trick SS to pass all subform request to recordEditForm()
            $recordsFieldList,
            $actions
        );

        if ($crumbs && $crumbs->count() >= 2) {
            $bulkEditForm->Backlink = $one_level_up->Link;
        }

        //override form action URL back to bulkEditForm
        //and add record ids GET var
        $bulkEditForm->setAttribute(
            'action',
            $this->Link('bulkEditForm?records[]='.implode('&', $recordList))
        );

        return $bulkEditForm;
    }
605664
public function washCreateForm() {

        // An array to hold the fields we'll neeed to INSERT the record
        $data = [];

        // Wash the input fields
        $data['to_email_address'] = trim($this->request->input('to_email_address'));
        $data['to_name']          = $this->genericWashText($this->request->input('to_name'));
        $data['subject']          = $this->genericWashText($this->request->input('subject'));
        $data['body']             = $this->genericWashText($this->request->input('body'));

        return $data;
    }
253759
protected function _prepareForm()
    {
        $form = $this->formFactory->create();
        $this->setForm($form);

        /** @var \Mirasvit\Blog\Model\Post $post */
        $post = $this->registry->registry('current_model');

        $fieldset = $form->addFieldset('image_fieldset', [
            'class'  => 'blog__post-fieldset',
            'legend' => __('Featured Image'),
        ]);

        $fieldset->addField('featured_image', 'image', [
            'required' => false,
            'name'     => 'featured_image',
            'value'    => $post->getFeaturedImageUrl(),
        ]);

        $fieldset->addField('featured_alt', 'text', [
            'required' => false,
            'label'   => __('Alt'),
            'name'     => 'post[featured_alt]',
            'value'    => $post->getFeaturedAlt(),
        ]);

        $fieldset->addField('featured_show_on_home', 'checkbox', [
            'label'   => __('Is show on Blog Home page'),
            'name'    => 'post[featured_show_on_home]',
            'value'   => 1,
            'checked' => $post->getFeaturedShowOnHome(),
        ]);

        return parent::_prepareForm();
    }
821225
protected function buildForm()
    {
        if ($this->form) {
            return;
        }

        // append parent object if any
        // todo : clean the way the Admin class can retrieve set the object
        if ($this->isChild() && $this->getParentAssociationMapping()) {
            $parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));

            $propertyAccessor = $this->getConfigurationPool()->getPropertyAccessor();
            $propertyPath = new PropertyPath($this->getParentAssociationMapping());

            $object = $this->getSubject();

            $value = $propertyAccessor->getValue($object, $propertyPath);

            if (\is_array($value) || ($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
                $value[] = $parent;
                $propertyAccessor->setValue($object, $propertyPath, $value);
            } else {
                $propertyAccessor->setValue($object, $propertyPath, $parent);
            }
        }

        $formBuilder = $this->getFormBuilder();
        $formBuilder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
            $this->preValidate($event->getData());
        }, 100);

        $this->form = $formBuilder->getForm();
    }
962635
private function buildEditForm()
    {
        $form = '';
        foreach ($this->fields as $field) {
            $title = addslashes($field->label);
            $label = $field->title;
            if (in_array($field->validation,
                    $this->starred) && $field->type != 'password' && $field->type != 'file' && $field->type != 'photo'
            ) {
                $title .= '*';
            }
            if ($field->type == 'relationship') {
                $label = $field->relationship_name . '_id';
            }
            if ($field->type == 'checkbox') {
                $field->default = '$' . $this->model . '->' . $label . ' == 1';
            }
            $temp = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'fields' . DIRECTORY_SEPARATOR . $field->type);
            $temp = str_replace([
                'old(\'$LABEL$\')',
                '$LABEL$',
                '$TITLE$',
                '$VALUE$',
                '$STATE$',
                '$SELECT$',
                '$TEXTEDITOR$',
                '$HELPER$',
                '$WIDTH$',
                '$HEIGHT$',
            ], [
                'old(\'$LABEL$\',$' . $this->resource . '->' . $label . ')',
                $label,
                $title,
                $field->type != 'radio' ?
                    $field->value != '' ? ', "' . $field->value . '"' : ''
                    : "'$field->value'",
                $field->default,
                '$' . $field->relationship_name,
                $field->texteditor == 1 ? ' ckeditor' : '',
                $this->helper($field->helper),
                $field->dimension_w,
                $field->dimension_h,
            ], $temp);
            $form .= $temp;
        }
        $this->formFieldsEdit = $form;
    }
1110152
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'
                        ]
            ]
        );

        // Prepare CSS
        $fieldsCss = 'width:100%;';
        $readOnlyCss = 'color:#777777;background-color:#dddddd;';
        
        // HTML prefix
        $form->setHtmlIdPrefix('ckom2_grid_');

        // Freeze in edit mode state
        $freezeInEditMode = false;
        $freezeInNewMode = false;

        // Build the form
        if ($model->getEntityId()) {
            $fieldset = $form->addFieldset(
                'base_fieldset',
                ['legend' => __('Editing subscription : %1', $model->getTrackId()), 'class' => 'fieldset-wide']
            );

            // Add id field
            $fieldset->addField('id', 'hidden', ['name' => 'id']);

            // Set the frozen field state
            $freezeInEditMode = true;

        } else {
            $fieldset = $form->addFieldset(
                'base_fieldset',
                ['legend' => __('Adding Subscription'), 'class' => 'fieldset-wide']
            );

            // Set the frozen field state
            $freezeInNewMode = true;
        }

        $fieldset->addField(
            'subscription_status',
            'select',
            [
                'name' => 'subscription_status',
                'label' => __('Status'),
                'id' => 'subscription_status',
                'title' => __('Status'),
                'values' => $this->_statusOptions->getOptionArray(),
                'class' => 'status',
                'required' => true,
                'disabled' => $freezeInNewMode,
                'style' => $fieldsCss . (($freezeInNewMode) ? $readOnlyCss : ''),
            ]
        );

        $fieldset->addField(
            'start_date',
            'date',
            [
                'name' => 'start_date',
                'label' => __('Start date'),
                'id' => 'start_date',
                'title' => __('Start date'),
                'class' => 'required-entry',
                'required' => true,
                'date_format' => 'yyyy-MM-dd',
                'time_format' => 'hh:mm:ss',
                'style' => $fieldsCss,
            ]
        );

        $fieldset->addField(
            'card_id',
            'select',
            [
                'name' => 'card_id',
                'label' => __('Payment method'),
                'id' => 'card_id',
                'title' => __('Payment method'),
                'values' => $this->_userCardsOptions->getOptions(),
                'class' => 'required-entry',
                'required' => true,
                'style' => $fieldsCss,
                'after_element_html' => '<div></div>',
            ]
        );

        $fieldset->addField(
            'track_id',
            'text',
            [
                'name' => 'track_id',
                'label' => __('Track ID'),
                'id' => 'track_id',
                'title' => __('Track ID'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
            ]
        );
        
        $fieldset->addField(
            'plan_id',
            'select',
            [
                'name' => 'plan_id',
                'label' => __('Payment plan'),
                'id' => 'track_id',
                'title' => __('Payment plan'),
                'values' => $this->_paymentPlanOptions->getOptionArray(),
                'class' => 'required-entry',
                'required' => true,
                'disabled' => $freezeInEditMode,
                'style' => $fieldsCss . (($freezeInEditMode) ? $readOnlyCss : ''),
            ]
        );

        $fieldset->addField(
            'user_id',
            'select',
            [
                'name' => 'user_id',
                'label' => __('Customer'),
                'id' => 'user_id',
                'title' => __('Customer'),
                'values' => $this->_userListOptions->getOptionArray(),
                'class' => 'required-entry',
                'required' => true,
                'disabled' => $freezeInEditMode,
                'style' => $fieldsCss . (($freezeInEditMode) ? $readOnlyCss : ''),
            ]
        );

        $fieldset->addField(
            'recurring_count_left',
            'text',
            [
                'name' => 'recurring_count_left',
                'label' => __('Recurring count left'),
                'id' => 'recurring_count_left',
                'title' => __('Recurring count left'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
                'after_element_html' => $this->_renderTooltip('Number of transactions remaining in the recurring plan.'),
            ]
        );

        $fieldset->addField(
            'total_collection_count',
            'text',
            [
                'name' => 'total_collection_count',
                'label' => __('Total collection count'),
                'id' => 'total_collection_count',
                'title' => __('Total collection count'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
                'after_element_html' => $this->_renderTooltip('Total number of transactions that will be applied against the card.'),
            ]
        );

        $fieldset->addField(
            'total_collection_value',
            'text',
            [
                'name' => 'total_collection_value',
                'label' => __('Total collection value'),
                'id' => 'total_collection_value',
                'title' => __('Total collection value'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
                'after_element_html' => $this->_renderTooltip('Total value of transactions that will be applied against the card.'),
            ]
        );

        $fieldset->addField(
            'previous_recurring_date',
            'text',
            [
                'name' => 'previous_recurring_date',
                'label' => __('Previous recurring date'),
                'id' => 'previous_recurring_date',
                'title' => __('Previous recurring date'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
                'after_element_html' => $this->_renderTooltip('Date of last recurring transaction in "YYYY-MM-DD" format.'),
            ]
        );

        $fieldset->addField(
            'next_recurring_date',
            'text',
            [
                'name' => 'next_recurring_date',
                'label' => __('Next recurring date'),
                'id' => 'next_recurring_date',
                'title' => __('Next recurring date'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss. $readOnlyCss,
                'after_element_html' => $this->_renderTooltip('Date of the next recurring transaction in "YYYY-MM-DD" format. This is especially useful when the merchant has applied a double recurring plan.'),
            ]
        );

        $fieldset->addField(
            'created_at',
            'text',
            [
                'name' => 'created_at',
                'label' => __('Created'),
                'id' => 'recurring_count',
                'title' => __('Created'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss . $readOnlyCss,
            ]
        );

        $fieldset->addField(
            'updated_at',
            'text',
            [
                'name' => 'updated_at',
                'label' => __('Updated'),
                'id' => 'updated_at',
                'title' => __('Updated'),
                'placeholder' => __('Generated automatically'),
                'readonly' => true,
                'style' => $fieldsCss . $readOnlyCss,
            ]
        );

        $form->setValues($model->getData());
        $form->setUseContainer(true);
        $this->setForm($form);
 
        return parent::_prepareForm();
    }
792725
protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array(
            'id' => 'edit_form',
            'action' => $this->getData('action'),
            'method' => 'post'
        ));
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
128804
public function create()
    {
        $class = $this->getClass();
        $form = new $class();

        $schema = $this->schemaManager->create();
        $schema->setObjectClass($this->postManager->getClass());

        $form->setSchema($schema);

        return $form;
    }
176470
public function AttendeeForm() {
		$form = new EventAttendeeForm($this, "AttendeeForm");
		$this->extend("updateAttendeeForm", $form, $this->registration);
		if ($this->BackURL) {
			$form->addCancelLink($this->BackURL);
		}
		return $form;
	}
591344
public function CreationForm()
    {
        /** @var FieldList $fields */
        $fields = singleton($this->getRecordType())->getFrontEndFields();
        $fields->push(new HiddenField('ID'));
        $form = new Form(
            $this,
            'CreationForm',
            $fields,
            new FieldList(
                new FormAction('doSave', 'Save'),
                new FormAction('doCancel', 'Cancel')
            ));
        return $form;
    }
3611
protected function _prepareForm()
    {
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action')]]
        );

        $thesaurusTypes = [
            ['value' => ThesaurusInterface::TYPE_SYNONYM, 'label' => __('Synonym')],
            ['value' => ThesaurusInterface::TYPE_EXPANSION, 'label' => __('Expansion')],
        ];

        $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Type')]);

        $fieldset->addField(
            'type',
            'select',
            [
                'name' => 'type',
                'label' => __('Thesaurus Type'),
                'title' => __('Thesaurus Type'),
                'values' => $thesaurusTypes,
            ]
        );

        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();
    }
684166
public function form()
    {
        return Admin::form(Permission::class, function (Form $form) {
            $form->display('id', 'ID');

            $form->text('slug', trans('admin.slug'))->rules('required');
            $form->text('name', trans('admin.name'))->rules('required');

            $form->multipleSelect('http_method', trans('admin.http.method'))
                ->options($this->getHttpMethodsOptions())
                ->help(trans('admin.all_methods_if_empty'));
            $form->textarea('http_path', trans('admin.http.path'));

            $form->display('created_at', trans('admin.created_at'));
            $form->display('updated_at', trans('admin.updated_at'));
        });
    }
653191
public function form()
    {
        return Administrator::form(function (Form $form) {
            $form->display('id', 'ID');

            $form->text('username', trans('admin.username'))->rules('required');
            $form->text('name', trans('admin.name'))->rules('required');
            $form->image('avatar', trans('admin.avatar'));
            $form->password('password', trans('admin.password'))->rules('required|confirmed');
            $form->password('password_confirmation', trans('admin.password_confirmation'))->rules('required')
                ->default(function ($form) {
                    return $form->model()->password;
                });

            $form->ignore(['password_confirmation']);

            $form->multipleSelect('roles', trans('admin.roles'))->options(Role::all()->pluck('name', 'id'));
            $form->multipleSelect('permissions', trans('admin.permissions'))->options(Permission::all()->pluck('name', 'id'));

            $form->display('created_at', trans('admin.created_at'));
            $form->display('updated_at', trans('admin.updated_at'));

            $form->saving(function (Form $form) {
                if ($form->password && $form->model()->password != $form->password) {
                    $form->password = bcrypt($form->password);
                }
            });
        });
    }
700320
public function editAction()
    {
        $form = $this->getEditForm();
        $entity = $form->getObject();
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost()->toArray();
            $entityManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
            $hydrator = new DoctrineHydrator($entityManager);
            $hydrator->hydrate($data, $entity);

            if ($form->isValid()) {
                $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
                $objectManager->persist($entity);
                $objectManager->flush();
                $controller = explode('/', $this->getRequest()->getUri()->getPath())[2];
                if (!$this->getRequest()->isXmlHttpRequest()) {
                    return $this->redirect()->toRoute(null, ['controller' => $controller]);
                }
                return;
            } else {
                $this->getResponse()->setStatusCode(400);
            }
        }
        $viewModel = $this->getViewModel();
        $viewModel->setTerminal($this->getRequest()->isXmlHttpRequest());

        return $viewModel->setVariables(['form' => $form]);
    }