Form->input(), * - requirements: boolean, if false is passed the field is skipped * - metafields: fields that are outside of the scope of the form itself - use these to define dynamic form fields, or anything that will feed into the regular fields via JS population * - submit: The submit button itself. By default it will simply submit to the form as defined via the 'model' field */ $this->Form->setConfig('errorClass', 'is-invalid'); $modelForForm = empty($data['model']) ? h(\Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::classify($this->request->getParam('controller')))) : h($data['model']); $entity = isset($entity) ? $entity : null; $fieldsString = ''; $simpleFieldWhitelist = [ 'default', 'type', 'placeholder', 'label', 'empty', 'rows', 'div', 'required', 'templates', 'options', 'value', 'checked', ]; if (empty($data['url'])) { $data['url'] = ["controller" => $this->request->getParam('controller'), "action" => $this->request->getParam('url')]; } $formRandomValue = Cake\Utility\Security::randomString(8); $initSelect2 = false; $formCreate = $this->Form->create($entity, ['id' => 'form-' . $formRandomValue]); $default_template = [ 'inputContainer' => '
{{content}}
', 'inputContainerError' => '
{{content}}
', 'label' => '{{text}}', 'input' => '', 'textarea' => '', 'select' => '', 'checkbox' => '', 'checkboxFormGroup' => '{{label}}', 'radio' => '', 'radioWrapper' => '{{label}}', 'formGroup' => '
{{input}}{{error}}
', 'nestingLabel' => '{{hidden}}
{{text}}
{{input}}
', 'option' => '', 'optgroup' => '{{content}}', 'select' => '', 'error' => '
{{content}}
', 'errorList' => '', 'errorItem' => '
  • {{text}}
  • ', ]; if (!empty($data['fields'])) { foreach ($data['fields'] as $fieldData) { if (!empty($fields)) { if (!in_array($fieldData['field'], $fields)) { continue; } } $initSelect2 = $initSelect2 || (!empty($fieldData['type']) && $fieldData['type'] == 'dropdown' && !empty($fieldData['select2'])); $formTemplate = $default_template; if (!empty($fieldData['floating-label'])) { $formTemplate['inputContainer'] = '
    {{content}}
    '; $formTemplate['label'] = '{{text}}'; $formTemplate['formGroup'] = '{{input}}{{label}}'; $fieldData['placeholder'] = !empty($fieldData['label']) ? $fieldData['label'] : h($fieldData['field']); } if (!empty($data['templates'])) { $formTemplate = array_merge($formTemplate, $data['templates']); } // we reset the template each iteration as individual fields might override the defaults. $this->Form->setConfig($formTemplate); $this->Form->setTemplates($formTemplate); if (isset($fieldData['requirements']) && !$fieldData['requirements']) { continue; } $fieldsString .= $this->element( 'genericElements/Form/fieldScaffold', [ 'fieldData' => $fieldData, 'form' => $this->Form, 'simpleFieldWhitelist' => $simpleFieldWhitelist ] ); } } $metaTemplateString = ''; if (!empty($entity['MetaTemplates']) && count($entity['MetaTemplates']) > 0) { $metaTemplateString = $this->element( 'genericElements/Form/metaTemplateScaffold', [ 'form' => $this->Form, ] ); } $submitButtonData = ['model' => $modelForForm, 'formRandomValue' => $formRandomValue]; if (!empty($data['submit'])) { $submitButtonData = array_merge($submitButtonData, $data['submit']); } if (!empty($data['ajaxSubmit'])) { $submitButtonData['ajaxSubmit'] = $ajaxSubmit; } $ajaxFlashMessage = ''; if (!empty($ajax)) { $ajaxFlashMessage = sprintf( '
    %s
    ', $this->Flash->render() ); } $formEnd = $this->Form->end(); $actionName = h(\Cake\Utility\Inflector::humanize($this->request->getParam('action'))); $modelName = h(\Cake\Utility\Inflector::humanize(\Cake\Utility\Inflector::singularize($this->request->getParam('controller')))); if (!empty($ajax)) { $seedModal = 'mseed-' . mt_rand(); echo $this->Bootstrap->modal([ 'title' => empty($data['title']) ? sprintf('%s %s', $actionName, $modelName) : h($data['title']), 'bodyHtml' => $this->element('genericElements/Form/formLayouts/formRaw', [ 'data' => $data, 'formCreate' => $formCreate, 'ajaxFlashMessage' => $ajaxFlashMessage, 'fieldsString' => $fieldsString, 'formEnd' => $formEnd, 'metaTemplateString' => $metaTemplateString, ]), 'size' => !empty($fieldsString) ? 'xl' : 'lg', 'type' => 'confirm', 'modalClass' => $seedModal, ]); } else if (!empty($raw)) { echo $this->element('genericElements/Form/formLayouts/formDefault', [ 'data' => $data, 'actionName' => $actionName, 'modelName' => $modelName, 'submitButtonData' => $submitButtonData, 'formCreate' => $formCreate, 'ajaxFlashMessage' => $ajaxFlashMessage, 'fieldsString' => $fieldsString, 'formEnd' => $formEnd, 'metaTemplateString' => $metaTemplateString, ]); } else { echo $this->element('genericElements/Form/formLayouts/formDefault', [ 'data' => $data, 'actionName' => $actionName, 'modelName' => $modelName, 'submitButtonData' => $submitButtonData, 'formCreate' => $formCreate, 'ajaxFlashMessage' => $ajaxFlashMessage, 'fieldsString' => $fieldsString, 'formEnd' => $formEnd, 'metaTemplateString' => $metaTemplateString, ]); } ?>