Pluf Framework

Pluf Framework Commit Details


Date:2011-05-29 19:49:30 (13 years 6 months ago)
Author:Thomas Keller
Branch:develop, master
Commit:324ae60b390d91e85b0123b34da7253a18119b6a
Parents: 3f985c690c87a9629940e7419f15491ae3a35f55
Message:Add support for closures / lambdas as per-field validation methods

The syntax for closures is

$this->clean_foo = function($form) {
// process $form->cleaned_data['foo']
}

This eases the handling of dynamic form fields somewhat that all
share some basic validation code, but can occur multiple times.
Changes:

File differences

src/Pluf/Form.php
105105
106106
107107
108
108109
109110
110111
111112
112113
113114
114
115
116
115
116
117
118
119
120
121
117122
118123
119124
$this->cleaned_data = array();
$this->errors = array();
$form_methods = get_class_methods($this);
$form_vars = get_object_vars($this);
foreach ($this->fields as $name=>$field) {
$value = $field->widget->valueFromFormData($this->addPrefix($name),
$this->data);
try {
$value = $field->clean($value);
$this->cleaned_data[$name] = $value;
if (in_array('clean_'.$name, $form_methods)) {
$m = 'clean_'.$name;
$value = $this->$m();
$method = 'clean_'.$name;
if (in_array($method, $form_methods)) {
$value = $this->$method();
$this->cleaned_data[$name] = $value;
} else if (array_key_exists($method, $form_vars) &&
is_callable($this->$method)) {
$value = call_user_func($this->$method, $this);
$this->cleaned_data[$name] = $value;
}
} catch (Pluf_Form_Invalid $e) {

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.05576s using 13 queries.