/** * create Form element * * @param array $attributes * @return \static */ public static function form($attributes = array()) { $ajax = false; $prop = array('method' => 'post'); $gform = true; $token = false; foreach ($attributes as $key => $value) { if ($key === 'ajax' || $key === 'action' || $key === 'onsubmit' || $key === 'onbeforesubmit' || $key === 'elements' || $key === 'script' || $key === 'gform' || $key === 'token') { ${$key} = $value; } else { $prop[$key] = $value; } } if (isset($prop['id']) && $gform) { $script = 'new GForm("' . $prop['id'] . '"'; if (isset($action)) { if ($ajax) { $script .= ', "' . $action . '"'; if (isset($onbeforesubmit)) { $script .= ',null ,false , function(){return ' . $onbeforesubmit . '}'; } } else { $prop['action'] = $action; } } $script .= ')'; if (isset($onsubmit)) { $script .= '.onsubmit(' . $onsubmit . ')'; } $script .= ';'; $form_inputs = Form::get2Input(); } else { if (isset($action)) { $prop['action'] = $action; } if (isset($onsubmit)) { $prop['onsubmit'] = $onsubmit . '()'; } if (isset($onbeforesubmit)) { $prop['onbeforesubmit'] = $onbeforesubmit . '()'; } } self::$form = new static('form', $prop); self::$form->ajax = $ajax; self::$form->gform = $gform; if (!empty($form_inputs)) { self::$form->rows = $form_inputs; } if ($token) { self::$form->rows[] = '<input type="hidden" name="token" value="' . self::$request->createToken() . '">'; } if (isset($script)) { self::$form->javascript[] = $script; } return self::$form; }
/** * create Form element * * @param array $attributes * @return \Html */ public static function form($attributes = array()) { $ajax = false; $prop = array('method' => 'post'); foreach ($attributes as $key => $value) { if ($key === 'ajax' || $key === 'action' || $key === 'onsubmit' || $key === 'confirmsubmit' || $key === 'elements' || $key === 'script') { ${$key} = $value; } else { $prop[$key] = $value; } } if (isset($prop['id'])) { $script = 'new GForm("' . $prop['id'] . '"'; if (isset($action)) { if ($ajax) { $script .= ', "' . $action . '"'; if (isset($confirmsubmit)) { $script .= ',null ,false , function(){return ' . $confirmsubmit . '}'; } } else { $prop['action'] = $action; } } $script .= ')'; if (isset($onsubmit)) { $script .= '.onsubmit(' . $onsubmit . ')'; } $script .= ';'; } self::$form = new static('form', $prop); self::$form->rows = Form::get2Input(); if (isset($script)) { self::$form->javascript[] = $script; } return self::$form; }