Skip to content
Snippets Groups Projects
Commit ce3ceaeb authored by Jared Hancock's avatar Jared Hancock
Browse files

search: Fix saving of advanced search with custom fields

parent 605c313d
No related branches found
No related tags found
No related merge requests found
......@@ -128,7 +128,7 @@ class SearchAjaxAPI extends AjaxController {
else
$data[$name] = $info['value'];
}
$form = $search->getForm();
$form = $search->getForm($data);
$form->setSource($data);
if (!$data || !$form->isValid()) {
Http::response(422, 'Validation errors exist on form');
......@@ -137,6 +137,8 @@ class SearchAjaxAPI extends AjaxController {
$search->config = JsonDataEncoder::encode($form->getState());
if (isset($_POST['name']))
$search->title = $_POST['name'];
elseif ($search->__new__)
Http::response(400, 'A name is required');
if (!$search->save()) {
Http::response(500, 'Internal error. Unable to update search');
}
......
......@@ -12,11 +12,13 @@ foreach ($form->errors(true) ?: array() as $message) {
}
$info = $search->getSearchFields($form);
foreach (array_keys($info) as $F) {
?><input type="hidden" name="fields[]" value="<?php echo $F; ?>"/><?php
}
$errors = !!$form->errors();
$inbody = false;
$first_field = true;
foreach ($form->getFields() as $name=>$field) {
?><input type="hidden" name="fields[]" value="<?php echo $name; ?>"/><?php
@list($name, $sub) = explode('+', $field->get('name'), 2);
if ($sub === 'search') {
if (!$first_field) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment