diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 5a2ecec0b2ea62290152a9d755253cd00cf4f290..4fd745e8c700a6909dc4de30d3b37359c889b1bf 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -448,7 +448,7 @@ class DynamicFormField extends VerySimpleModel { */ function setConfiguration(&$errors=array()) { $config = array(); - foreach ($this->getConfigurationForm() as $name=>$field) { + foreach ($this->getConfigurationForm($_POST)->getFields() as $name=>$field) { $config[$name] = $field->to_php($field->getClean()); $errors = array_merge($errors, $field->errors()); } diff --git a/include/class.forms.php b/include/class.forms.php index aa9405d80d056e0e8764c0b330d7469e14426798..d8c93f2c769accb26d38bbcb1d95f4f6731e74da 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -28,8 +28,11 @@ class Form { function __construct($fields=array(), $source=null, $options=array()) { $this->fields = $fields; - foreach ($fields as $f) + foreach ($fields as $k=>$f) { $f->setForm($this); + if (!$f->get('name') && $k) + $f->set('name', $k); + } if (isset($options['title'])) $this->title = $options['title']; if (isset($options['instructions'])) @@ -535,12 +538,21 @@ class FormField { return false; } - function getConfigurationForm() { + function getConfigurationForm($source=null) { if (!$this->_cform) { $type = static::getFieldType($this->get('type')); $clazz = $type[1]; $T = new $clazz(); - $this->_cform = $T->getConfigurationOptions(); + $config = $this->getConfiguration(); + $this->_cform = new Form($T->getConfigurationOptions(), $source); + if (!$source && $config) { + foreach ($this->_cform->getFields() as $name=>$f) { + if (isset($config[$name])) + $f->value = $config[$name]; + elseif ($f->get('default')) + $f->value = $f->get('default'); + } + } } return $this->_cform; } diff --git a/include/staff/templates/dynamic-field-config.tmpl.php b/include/staff/templates/dynamic-field-config.tmpl.php index da2621b3fef930186fe68339b3dbea4b974b9617..af257465289439f8748ffc948911be5fc62e2f1c 100644 --- a/include/staff/templates/dynamic-field-config.tmpl.php +++ b/include/staff/templates/dynamic-field-config.tmpl.php @@ -5,15 +5,9 @@ echo $field->get('id'); ?>"> <?php echo csrf_token(); - $config = $field->getConfiguration(); - $form = new Form($field->getConfigurationForm()); + $form = $field->getConfigurationForm(); echo $form->getMedia(); - foreach ($form->getFields() as $name=>$f) { - if (isset($config[$name])) - $f->value = $config[$name]; - else if ($f->get('default')) - $f->value = $f->get('default'); - ?> + foreach ($form->getFields() as $name=>$f) { ?> <div class="flush-left custom-field"> <div class="field-label"> <label for="<?php echo $f->getWidget()->name; ?>">