Пример #1
0
    public static function generate($structure, $data, $formData, $forma, $template, $extraFields = null, $adminka = true)
    {
        echo $template['formStart'];
        self::$adminka = $adminka;
        $form = new K_jformHelper();
        $form->begin($formData[0], $formData[1], array_merge(array('id' => 'x_form_' . $formData[2], 'enctype' => $formData[3]), isset($formData[4]) ? $formData[4] : array()));
        $structure = json_decode($structure);
        if (is_array($structure) && $structure) {
            foreach ($structure as $elementKey => $element) {
                if (self::convertTypes($element->type)) {
                    $type = self::convertTypes($element->type);
                    ob_start();
                    self::addField($form, $type, $element, isset($data[$element->values->name]) ? $data[$element->values->name] : '', $formData);
                    $fieldCode = ob_get_contents();
                    ob_end_clean();
                    echo self::template(isset($template['row_' . $type]) ? $template['row_' . $type] : $template['row'], array('label' => $element->values->label, 'class' => $element->values->class, 'element' => $fieldCode));
                }
            }
            if (isset($extraFields) && $extraFields) {
                foreach ($extraFields as $k => $v) {
                    $element = new stdClass();
                    $element->values->name = $k;
                    $element->values->value = $v;
                    $element->values->class = '';
                    $element->values->id = '';
                    self::addField($form, "hidden", $element, isset($data[$element->values->name]) ? $data[$element->values->name] : '', $formData);
                }
            }
        } else {
            echo '
				<div class="nNote nFailure hideit">
					<p><strong>Ошибка: </strong>Форма не найдена!</p>
				</div>
			';
        }
        $form->end();
        echo self::template($template['formEnd'], array('formid' => $formData[2]));
        if ($adminka) {
            echo '<script type="text/javascript">$("#x_form_' . $formData[2] . '").ajaxForm({beforeSubmit:function(){disableTree();},success: function(responseText, statusText, xhr, $form){ $("#x_formsuccess_' . $formData[2] . '").css("display", "block").animate({"opacity": 1.0}, 2000).html("<p>"+responseText+"</p>"); }});</script>';
        }
    }
Пример #2
0
 public function generateForm($structure, $data, $formData = array('', '', '', 'application/x-www-form-urlencoded', ''), $template = false, $extraFields = false, $adminka = true)
 {
     K_jForm::generate($structure, $data, $formData, $this->form, $template, $extraFields, $adminka);
 }