initial_value = $initial_value; $instance->form = array("input" => $initial_value); $instance->errors = array("input" => ""); return $instance; } public function action($action) { $this->action = $action; return $this; } public function rules($rules) { $this->rules += $rules; return $this; } public function messages($messages) { $this->messages += $messages; return $this; } public function callback($callback) { $this->callback = $callback; return $this; } public function validate() { $post = Validation::factory($_POST) ->add_callbacks("input", $this->callback); foreach ($this->rules as $rule) { $post->add_rules("input", $rule); } $valid = $post->validate(); $this->form = array_merge($this->form, $post->as_array()); $this->errors = array_merge($this->errors, $post->errors()); return $valid; } public function render() { $v = new View("in_place_edit.html"); $v->action = $this->action; $v->form = $this->form; $v->errors = $this->errors; foreach ($v->errors as $key => $error) { if (!empty($error)) { $v->errors[$key] = $this->messages[$error]; } } return $v->render(); } public function value() { return $this->form["input"]; } }