<?php defined('SYSPATH') OR die('No direct access allowed.'); class Form_Login extends Form { public static function meta() { return array( "fields" => array( "login" => Field::factory("Varchar"), "password" => Field::factory("Password"), ), "options" => array( // . . "valid_messages_file" => "login", // , messages "theme" => "base" // . base - , 2 : base, nolabels. nolabels base label ), ); } }
<form> <?php echo $form; ?> <input type="submit" value="Add"/> </form>
<form method="POST" role="form"> <?php foreach ($form as $field): ?> <div class="form-group"> <?php $field->css_class(array("form-control")); ?> <?php foreach ($field->errors() as $error): ?> <div class="alert alert-danger"> <?php echo $error; ?> </div> <?php endforeach; ?> <?php echo $field; ?> </div> <? endforeach; ?> <input type="submit" class="btn btn-primary" value="Add"/> </form>
class Form_Article extends ModelForm { public static function meta() { return array( "fields" => array( // . , . "image" => Field::factory("Image") ), "options" => array( "model" => ORM::factory("Article"), // "display_fields" => array("title", "body", "image"), // "valid_messages_file" => "news", // "except_fields" => array() // ), ); } }
Form::factory("Article", array(), $id);
Form::factory("Article", array("title" => "Hello, Habr!"));
public function action_add() { if ($this->request->method() == "POST") { $form = Form::factory("Article", $this->request->post()); $form->add_field( Field::factory("Hidden") ->name("user") ->value(Auth::instance() ->get_user()) ); if ($form->validate()) $form->save(); } }
<?php defined('SYSPATH') OR die('No direct access allowed.'); class Formset_News extends Formset { public static function meta() { return array( "base_form" => "News", "theme" => "bootstrap" ); } }
Source: https://habr.com/ru/post/216187/
All Articles