Create the form for adding/editing records
@return EventAttendeeForm
176470
public function AttendeeForm() {
		$form = new EventAttendeeForm($this, "AttendeeForm");
		$this->extend("updateAttendeeForm", $form, $this->registration);
		if ($this->BackURL) {
			$form->addCancelLink($this->BackURL);
		}
		return $form;
	}
1012654
private function insertFormEnd() {

		$this->html = preg_replace(
			'/\{\s*end_form\s*\}/i',
			'</form>',
			$this->html,
			-1,
			$count
		);

		// more than one closing tag found

		if($count > 1) {

			throw new HtmlFormException("Found more than one closing {end_form} tags.", HtmlFormException::INVALID_MARKUP);

		}

		// no closing tag

		if(!$count) {
			$this->html .= '</form>';
		}

		return $this;

	}
187011
function() {
		
		var newvalues, record;
		
	  	//Validate the Form
	  	if ( !this.dialog.getForm().validate() ) return ;
	   
		// Update the record
		if(!this.insertNewRecord){
						
			// Update the row
			newvalues = this.dialog.getValue();
			this.datatable.updateRow( this.selectedRecord , newvalues );

			// Get the new record
			record = this.datatable.getRecord(this.selectedRecord);
			
			// Fire the modify event
         this.itemModifiedEvt.fire(record);

		}
		// Adding new record
		else{
			// Insert a new row
	      this.datatable.addRow({});

			// Set the Selected Record
			var rowIndex = this.datatable.getRecordSet().getLength() - 1;
			this.selectedRecord = rowIndex;
			
			// Update the row
			newvalues = this.dialog.getValue();
			this.datatable.updateRow( this.selectedRecord , newvalues );
			
			// Get the new record
			record = this.datatable.getRecord(this.selectedRecord);
						
			// Fire the add event
         this.itemAddedEvt.fire(record);
		}
      
      this.dialog.hide();
   }
713342
public function edit()
    {
        // Validate form
        $form = $this->getForm('Edit' . $this->getEntityName());
        if (!$form->isValid()) {
            return false;
        }

        // Update account
        $now    = new \DateTime();
        $entity = $form->getData();
        $entity->setLastModified($now);

        // Trigger onedit
        $this->onEdit($entity);

        // Save
        return $this->save($this->getEntityName() . ' saved.', 'Unable to save ' . strtolower($this->getEntityName()) . '.');
    }
1281601
public function DeliveryForm()
    {
        $form = DeliveryDetailsForm::create($this, 'DeliveryForm');

        $data = Session::get("Checkout.DeliveryDetailsForm.data");
        if (is_array($data)) {
            $form->loadDataFrom($data);
        }

        $this->extend("updateDeliveryForm", $form);

        return $form;
    }
717523
public function Form()
    {
        $svc            = singleton(WorkflowService::class);
        $active         = $svc->getWorkflowFor($this->getContextObject());

        if (!$active) {
            return;
            //throw new Exception('Workflow not found, or not specified for Context Object');
        }

        $wfFields     = $active->getFrontEndWorkflowFields();
        $wfActions    = $active->getFrontEndWorkflowActions();
        $wfValidator  = $active->getFrontEndRequiredFields();

        //Get DataObject for Form (falls back to ContextObject if not defined in WorkflowAction)
        $wfDataObject = $active->getFrontEndDataObject();

        // set any requirements spcific to this contextobject
        $active->setFrontendFormRequirements();

        // hooks for decorators
        $this->extend('updateFrontEndWorkflowFields', $wfFields);
        $this->extend('updateFrontEndWorkflowActions', $wfActions);
        $this->extend('updateFrontEndRequiredFields', $wfValidator);
        $this->extend('updateFrontendFormRequirements');

        $form = new FrontendWorkflowForm($this, 'Form/' . $this->getContextID(), $wfFields, $wfActions, $wfValidator);

        $form->addExtraClass("fwf");

        if ($wfDataObject) {
            $form->loadDataFrom($wfDataObject);
        }

        return $form;
    }
1213583
public function Form()
    {
        $crumbs = $this->Breadcrumbs();
        
        if ($crumbs && $crumbs->count()>=2) {
            $one_level_up = $crumbs->offsetGet($crumbs->count()-2);
        }
        
        $record_ids = "";
        $query_string = "";
        $recordList = $this->getRecordIDList();
        
        foreach ($this->getRecordIDList() as $id) {
            $record_ids .= $id . ',';
            $query_string .= "records[]={$id}&";
        }
        
        // Cut off the last 2 parts of the string
        $record_ids = substr($record_ids, 0, -1);
        $query_string = substr($query_string, 0, -1);
        
        $form = new Form(
            $this,
            'Form',
            $fields = FieldList::create(
                HiddenField::create("RecordIDs", "", $record_ids),
                TagField::create(
                    'Tags',
                    null,
                    ContactTag::get()
                )->setDescription(_t(
                    "Contacts.TagDescription",
                    "List of tags related to this contact, seperated by a comma."
                ))->setShouldLazyLoad(true)
            ),
            $actions = FieldList::create(
                FormAction::create('doAddTags', _t("Contacts.Add", 'Add'))
                    ->setAttribute('id', 'bulkEditingSaveBtn')
                    ->addExtraClass('btn btn-success')
                    ->setAttribute('data-icon', 'accept')
                    ->setUseButtonTag(true),
                    
                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', '')
            )
        );
        
        if ($crumbs && $crumbs->count() >= 2) {
            $form->Backlink = $one_level_up->Link;
        }
        
        // override form action URL back to bulkEditForm
        // and add record ids GET var
        $form->setFormAction(
            $this->Link('Form?records[]='.implode('&', $recordList))
        );

        return $form;
    }
106358
private function setFileAction()
    {
        array_push($this->actions, 'file');

        $this->addForm = array_diff($this->addForm, ['files']);
        $this->editForm = array_diff($this->addForm, ['files']);

        $this->setModelDefaults('files', []);
        $this->setColumnFormat('files', 'files');

        return $this;
    }
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();
    }
1044264
public function definition() {
        global $PAGE;

        $mform = $this->_form;
        $starttime = isset($this->_customdata['starttime']) ? $this->_customdata['starttime'] : 0;
        $editoroptions = !(empty($this->_customdata['editoroptions'])) ? $this->_customdata['editoroptions'] : null;
        $courseid = !(empty($this->_customdata['courseid'])) ? $this->_customdata['courseid'] : null;

        $eventtypes = calendar_get_allowed_event_types($courseid);

        if (in_array(true, $eventtypes, true) === false) {
            print_error('nopermissiontoupdatecalendar');
        }

        $mform->setDisableShortforms();
        $mform->disable_form_change_checker();

        // Empty string so that the element doesn't get rendered.
        $mform->addElement('header', 'general', '');

        $this->add_default_hidden_elements($mform);

        // Event name field.
        $mform->addElement('text', 'name', get_string('eventname', 'calendar'), 'size="50"');
        $mform->addRule('name', get_string('required'), 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);

        // Event time start field.
        $mform->addElement('date_time_selector', 'timestart', get_string('date'), ['defaulttime' => $starttime]);

        // Add the select elements for the available event types.
        $this->add_event_type_elements($mform, $eventtypes);

        // Start of advanced elements.
        // Advanced elements are not visible to the user by default.
        // They are displayed through the user of a show more / less button.
        $mform->addElement('editor', 'description', get_string('eventdescription', 'calendar'), ['rows' => 3], $editoroptions);
        $mform->setType('description', PARAM_RAW);
        $mform->setAdvanced('description');

        $mform->addElement('text', 'location', get_string('location', 'moodle'), 'size="50"');
        $mform->setType('location', PARAM_RAW_TRIMMED);
        $mform->setAdvanced('location');

        // Add the variety of elements allowed for selecting event duration.
        $this->add_event_duration_elements($mform);

        // Add the form elements for repeating events.
        $this->add_event_repeat_elements($mform);

        // Add the javascript required to enhance this mform.
        $PAGE->requires->js_call_amd('core_calendar/event_form', 'init', [$mform->getAttribute('id')]);
    }
1058424
public function Form() {
		// The editing form hasn't been put in place by the 'edit' action
		// so lets just show the status form
		$append = '';
		if (!$this->form) {
			if (WikiPage::$show_edit_button || $this->data()->canEdit()) {
				// create the information form 
				$this->form = $this->StatusForm();
			}
		} else {
			// if we have got an editing form, then we'll add a New Page
			// form if we have permissions to do so
			if (Permission::check(MANAGE_WIKI_PAGES)) {
				$append = $this->CreatePageForm()->forTemplate();
			}
		}

		return $this->form->forTemplate() . $append;
	}
441256
protected function _prepareForm()
    {
        $model = $this->getModel();

        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
        );

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

        if ($model->getId()) {
            $fieldset->addField('thesaurus_id', 'hidden', ['name' => 'thesaurus_id']);
        }

        if ($model->getType()) {
            $fieldset->addField('type', 'hidden', ['name' => 'type']);
        }

        $this->initBaseFields($fieldset);
        $this->initTypeFields($fieldset, $model);

        $form->setValues($model->getData());

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

        return parent::_prepareForm();
    }
1291931
protected function createAttendee() {
		$attendee = EventAttendee::create();
		$attendee->RegistrationID = $this->registration->ID;
		return $attendee;
	}
978309
public function StatusForm() {
		$existing = $this->getEditingLocks($this->data());

		if ($existing && $existing['user'] != Member::currentUser()->Email) {
			$fields = FieldList::create(
							new ReadonlyField('ExistingEditor', '', _t('WikiPage.EXISTINGEDITOR', 'This page is currently locked for editing by ' . $existing['user'] . ' until ' . $existing['expires']))
			);
			$actions = FieldList::create();
		} else {
			$fields = FieldList::create();
			$actions = FieldList::create(
							new FormAction('startediting', _t('WikiPage.STARTEDIT', 'Edit Page'))
			);
		}

		return new Form($this, 'StatusForm', $fields, $actions);
	}
375777
public function createAction()
    {
        $request = $this->getRequest();
        // the key used to lookup the template
        $templateKey = 'edit';

        $this->admin->checkAccess('create');

        $class = new \ReflectionClass($this->admin->hasActiveSubClass() ? $this->admin->getActiveSubClass() : $this->admin->getClass());

        if ($class->isAbstract()) {
            return $this->renderWithExtraParams(
                '@SonataAdmin/CRUD/select_subclass.html.twig',
                [
                    'base_template' => $this->getBaseTemplate(),
                    'admin' => $this->admin,
                    'action' => 'create',
                ],
                null
            );
        }

        $newObject = $this->admin->getNewInstance();

        $preResponse = $this->preCreate($request, $newObject);
        if (null !== $preResponse) {
            return $preResponse;
        }

        $this->admin->setSubject($newObject);

        $form = $this->admin->getForm();

        if (!\is_array($fields = $form->all()) || 0 === \count($fields)) {
            throw new \RuntimeException(
                'No editable field defined. Did you forget to implement the "configureFormFields" method?'
            );
        }

        $form->setData($newObject);
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $isFormValid = $form->isValid();

            // persist if the form was valid and if in preview mode the preview was approved
            if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
                $submittedObject = $form->getData();
                $this->admin->setSubject($submittedObject);
                $this->admin->checkAccess('create', $submittedObject);

                try {
                    $newObject = $this->admin->create($submittedObject);

                    if ($this->isXmlHttpRequest()) {
                        return $this->renderJson([
                            'result' => 'ok',
                            'objectId' => $this->admin->getNormalizedIdentifier($newObject),
                            'objectName' => $this->escapeHtml($this->admin->toString($newObject)),
                        ], 200, []);
                    }

                    $this->addFlash(
                        'sonata_flash_success',
                        $this->trans(
                            'flash_create_success',
                            ['%name%' => $this->escapeHtml($this->admin->toString($newObject))],
                            'SonataAdminBundle'
                        )
                    );

                    // redirect to edit mode
                    return $this->redirectTo($newObject);
                } catch (ModelManagerException $e) {
                    $this->handleModelManagerException($e);

                    $isFormValid = false;
                }
            }

            // show an error message if the form failed validation
            if (!$isFormValid) {
                if (!$this->isXmlHttpRequest()) {
                    $this->addFlash(
                        'sonata_flash_error',
                        $this->trans(
                            'flash_create_error',
                            ['%name%' => $this->escapeHtml($this->admin->toString($newObject))],
                            'SonataAdminBundle'
                        )
                    );
                }
            } elseif ($this->isPreviewRequested()) {
                // pick the preview template if the form was valid and preview was requested
                $templateKey = 'preview';
                $this->admin->getShow();
            }
        }

        $formView = $form->createView();
        // set the theme for the current Admin Form
        $this->setFormTheme($formView, $this->admin->getFormTheme());

        // NEXT_MAJOR: Remove this line and use commented line below it instead
        $template = $this->admin->getTemplate($templateKey);
        // $template = $this->templateRegistry->getTemplate($templateKey);

        return $this->renderWithExtraParams($template, [
            'action' => 'create',
            'form' => $formView,
            'object' => $newObject,
            'objectId' => null,
        ], null);
    }
606732
public function ItemEditForm() {
        $form=parent::ItemEditForm();
        
        if($form) {
            if($this->record && $this->record->exists()) {
                $kapostBase=KapostAdmin::config()->kapost_base_url;
                if($kapostBase[strlen($kapostBase)-1]!='/') {
                    $kapostBase.='/';
                }
                
                $form->Fields()->addFieldToTab('Root.Main', $field=ReadonlyField::create(
                                                                    'KapostRefID_linked',
                                                                    $this->record->fieldLabel('KapostRefID'),
                                                                    (!empty($kapostBase) ? '<a href="'.htmlentities($kapostBase.'posts/'.$this->record->KapostRefID).'" target="_blank">'.htmlentities($this->record->KapostRefID).'</a>':$this->record->KapostRefID)
                                                                )->setForm($form));
                $field->dontEscape=true;
                
                
                $form->Actions()->insertBefore(
                                                FormAction::create('doConvertPost', _t('KapostAdmin.CONVERT_OBJECT', '_Convert Object'))
                                                    ->setUseButtonTag(true)
                                                    ->addExtraClass('ss-ui-action-constructive kapost-action-convert')
                                                    ->setAttribute('data-icon', 'kapost-convert')
                                                    ->setForm($form)
                                            , 'action_doDelete');
            }
            
            
            $form->addExtraClass('KapostAdmin');
        }
        
        return $form;
    }
479688
public function getFieldEditorGrid()
    {
        Requirements::javascript('silverstripe/userforms:client/dist/js/userforms-cms.js');

        $fields = $this->owner->Fields();

        $this->createInitialFormStep(true);

        $editableColumns = new GridFieldEditableColumns();
        $fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
        $editableColumns->setDisplayFields([
            'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
                if ($record instanceof EditableFormField) {
                    return $record->getInlineClassnameField($column, $fieldClasses);
                }
            },
            'Title' => function ($record, $column, $grid) {
                if ($record instanceof EditableFormField) {
                    return $record->getInlineTitleField($column);
                }
            }
        ]);

        $config = GridFieldConfig::create()
            ->addComponents(
                $editableColumns,
                new GridFieldButtonRow(),
                (new GridFieldAddClassesButton(EditableTextField::class))
                    ->setButtonName(_t(__CLASS__.'.ADD_FIELD', 'Add Field'))
                    ->setButtonClass('btn-primary'),
                (new GridFieldAddClassesButton(EditableFormStep::class))
                    ->setButtonName(_t(__CLASS__.'.ADD_PAGE_BREAK', 'Add Page Break'))
                    ->setButtonClass('btn-secondary'),
                (new GridFieldAddClassesButton([EditableFieldGroup::class, EditableFieldGroupEnd::class]))
                    ->setButtonName(_t(__CLASS__.'.ADD_FIELD_GROUP', 'Add Field Group'))
                    ->setButtonClass('btn-secondary'),
                $editButton = new GridFieldEditButton(),
                new GridFieldDeleteAction(),
                new GridFieldToolbarHeader(),
                new GridFieldOrderableRows('Sort'),
                new GridFieldDetailForm()
            );

        $editButton->removeExtraClass('grid-field__icon-action--hidden-on-hover');

        $fieldEditor = GridField::create(
            'Fields',
            '',
            $fields,
            $config
        )->addExtraClass('uf-field-editor');

        return $fieldEditor;
    }