diff --git a/include/ajax.forms.php b/include/ajax.forms.php index 8044fafc32c7b1d9e77ee93f341d14903627d5f4..e53b91348a4d47b3a0b0bc44b001051f292f22d4 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -24,8 +24,18 @@ class DynamicFormsAjaxAPI extends AjaxController { $_SESSION[':form-data'] = array_merge($_SESSION[':form-data'], $_GET); } - if ($form = $topic->getForm()) + if ($form = $topic->getForm()) { + ob_start(); $form->getForm($_SESSION[':form-data'])->render(!$client); + $html = ob_get_clean(); + ob_start(); + print $form->getMedia(); + $media = ob_get_clean(); + } + return $this->encode(array( + 'media' => $media, + 'html' => $html, + )); } function getClientFormsForHelpTopic($topic_id) { diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 19ac4bb9fc4caede3b42a6150091bd843ec042b0..1b31e882d75025c248c48969627a2af75d617471 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -62,7 +62,9 @@ class DynamicForm extends VerySimpleModel { } function getDynamicFields() { - if (!$this->_dfields && isset($this->id)) { + if (!isset($this->id)) + return array(); + elseif (!$this->_dfields) { $this->_dfields = DynamicFormField::objects() ->filter(array('form_id'=>$this->id)) ->all(); @@ -1009,12 +1011,10 @@ class DynamicFormEntryAnswer extends VerySimpleModel { } function getValue() { - $value = $this->getField()->to_php( - $this->get('value'), $this->get('value_id')); - if (!$value && $this->getEntry()->getSource()) { - return $this->getEntry()->getField( - $this->getField()->get('name'))->getClean(); - } + if (!$this->_value && isset($this->value)) + $this->_value = $this->getField()->to_php( + $this->get('value'), $this->get('value_id')); + return $this->_value; } function getIdValue() { diff --git a/include/client/open.inc.php b/include/client/open.inc.php index 26df0a5a367816f51cb8d3eeb969229bd39200aa..821aa6ef9cc8661e5126b070dc5d35fedc09d1df 100644 --- a/include/client/open.inc.php +++ b/include/client/open.inc.php @@ -34,9 +34,16 @@ if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) { <td> <select id="topicId" name="topicId" onchange="javascript: var data = $(':input[name]', '#dynamic-form').serialize(); - $('#dynamic-form').load( - 'ajax.php/form/help-topic/' + this.value, data); - "> + $.ajax( + 'ajax.php/form/help-topic/' + this.value, + { + data: data, + dataType: 'json', + success: function(json) { + $('#dynamic-form').empty().append(json.html); + $(document.head).append(json.media); + } + });"> <option value="" selected="selected">— <?php echo __('Select a Help Topic');?> —</option> <?php if($topics=Topic::getPublicHelpTopics()) { diff --git a/include/staff/templates/dynamic-form.tmpl.php b/include/staff/templates/dynamic-form.tmpl.php index 8ed99010089804b4a63f513b238c1ef50a56719c..3987d9ee0ab9582db3fbcd57d669621477da6846 100644 --- a/include/staff/templates/dynamic-form.tmpl.php +++ b/include/staff/templates/dynamic-form.tmpl.php @@ -7,8 +7,6 @@ if (isset($options['entry']) && $options['mode'] == 'edit' ) return; -print $form->getMedia(); - if (isset($options['entry']) && $options['mode'] == 'edit') { ?> <tbody> <?php } ?> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index 96d1abe6fc943457bf67cbfd3459582dd5b0da2c..2001e28505a525d15f0244f8d809c0e88d33bb8a 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -134,6 +134,7 @@ if ($_POST) <?php if ($forms) foreach ($forms as $form) { $form->render(true, false, array('mode'=>'edit','width'=>160,'entry'=>$form)); + print $form->getForm()->getMedia(); } ?> </table> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 3c8b8f2421ee1840c2ddae3e2574abb4d387c1b0..39acb0864519519c278c7c4d28771476a4042c20 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -132,9 +132,16 @@ if ($_POST) <td> <select name="topicId" onchange="javascript: var data = $(':input[name]', '#dynamic-form').serialize(); - $('#dynamic-form').load( - 'ajax.php/form/help-topic/' + this.value, data); - "> + $.ajax( + 'ajax.php/form/help-topic/' + this.value, + { + data: data, + dataType: 'json', + success: function(json) { + $('#dynamic-form').empty().append(json.html); + $(document.head).append(json.media); + } + });"> <?php if ($topics=Topic::getHelpTopics()) { if (count($topics) == 1) @@ -252,6 +259,7 @@ if ($_POST) <tbody id="dynamic-form"> <?php if ($form) { + print $form->getForm()->getMedia(); include(STAFFINC_DIR . 'templates/dynamic-form.tmpl.php'); } ?> diff --git a/scp/forms.php b/scp/forms.php index 5bf9415e98e5b6042c1870364d0cb18833489518..3b7e6af04e7f137af5732a6d7866fb169fd2a495 100644 --- a/scp/forms.php +++ b/scp/forms.php @@ -11,6 +11,7 @@ if($_POST) { $required = array('title'); $max_sort = 0; $form_fields = array(); + $names = array(); switch(strtolower($_POST['do'])) { case 'update': foreach ($fields as $f) @@ -20,7 +21,6 @@ if($_POST) { elseif (isset($_POST[$f])) $form->set($f, $_POST[$f]); $form->save(true); - $names = array(); foreach ($form->getDynamicFields() as $field) { $id = $field->get('id'); if ($_POST["delete-$id"] == 'on' && $field->isDeletable()) {