From 4610fc8e7f32f1a582b5f6c9c25714151b9a2967 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 16 Nov 2008 07:51:42 +0000 Subject: Create Forge::add_rules_from() which pulls validation rules from the model and associates them with the form. This replaces the various _add_validation_rules() functions in the user and comment modules. Move user edit form into user helper for consistency with the comment module. Implement missing _form method in the user controller. --- core/libraries/MY_Forge.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core') diff --git a/core/libraries/MY_Forge.php b/core/libraries/MY_Forge.php index a954eb9e..0aedac86 100644 --- a/core/libraries/MY_Forge.php +++ b/core/libraries/MY_Forge.php @@ -3,4 +3,18 @@ class Forge extends Forge_Core { public function render($template="form.html", $custom=false) { return parent::render($template, $custom); } + + /** + * Associate validation rules defined in the model with this form. + */ + public function add_rules_from($model) { + foreach ($this->inputs as $name => $input) { + if (isset($input->inputs)) { + $input->add_rules_from($model); + } + if (isset($model->rules[$name])) { + $input->rules($model->rules[$name]); + } + } + } } \ No newline at end of file -- cgit v1.2.3