_getNewForm(); $form->setDefaults([ 'content' => $this->_getTemplateContent(), 'data' => json_encode($this->_getTemplateData()), ]); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _getTemplateContent() { $html = '
Name: {name}
' . 'Phone: {phone}
' . 'No Phone Number
'; return $html; } protected function _getTemplateData() { return [ 'name' => 'User Name', 'phone' => '', ]; } protected function _doInsert() { $form = $this->_getNewForm(); if ($form->validate()) { $data = $form->getValues(); if (null === ($templateData = json_decode($data['data'], true))) { $templateData = $this->_getTemplateData(); } $template = new Qs_Template(); $template->setDynamic(true); $template->addArrayDataSource($templateData); $html = $template->render($data['content']); $form->getElement('dump')->setValue(htmlspecialchars($html)); } $this->_addFormItem($form); return $this; } protected function _getNewForm(array $options = []) { $form = new Qs_Form($this->_getFormOptions()); $form->addElement('hidden', 'action', array('value' => 'insert')); $form->addElement('static', 'dump', array('label' => 'SUBMITTED VALUES')); $form->addElement('textarea', 'data', array('label' => 'Template Data (JSON encoded)')); $form->addElement( 'htmlEditor', 'content', [ 'label' => 'Template', 'toolbar' => 'DefaultTemplate', 'mode' => 'view', 'templatePlaceholders' => ['name', 'phone'], ] ); return $form; } }