function SPITFORM($formfields, $errors) { global $form, $fields, $root, $template, $prevsearch, $this_user; if ($savedsearches = $root->SavedSearches($this_user)) { $action = CreateURL("template_search", $template); echo "<script language=JavaScript>\n function PreviousSearch() {\n var index = document.prevsearch.prevselect.selectedIndex;\n document.prevsearch.target='_self';\n document.prevsearch.action='{$action}' + '&prevsearch=' +\n document.prevsearch.prevselect.options[index].value;\n document.prevsearch.submit();\n }\n </script>\n"; echo "<form name=prevsearch onsubmit=\"return false;\"\n action=foo method=post>\n"; echo FormRenderSelect("savedsearches", array('#type' => 'select', '#default' => 'Choose a Previous Search', '#options' => $savedsearches, '#name' => 'prevselect', '#javascript' => "onchange=\"PreviousSearch();\"")); echo "</form>\n"; } if (isset($prevsearch)) { # # Lets add a primitive mechanism to allow saved search deletion. # Add a delete button to the saved search row. # $fields['save']['#elements']['deletesearch'] = array('#type' => 'image', '#value' => "{$prevsearch}", '#image' => "trash.jpg"); } $fields['submits'] = array('#type' => 'list', '#colspan' => TRUE, '#elements' => array('addclause' => array('#type' => 'submit', '#value' => "Add Clause"), 'search' => array('#type' => 'submit', '#value' => "Search"))); echo "<center>"; FormRender($form, $errors, $fields, $formfields); echo "</center>"; }
function FormRenderElement($name, $attributes, $submitted) { $field_html = null; # # The value that was submitted overrides the value in the attributes. # For most things, we just munge the attributes field. # if ($submitted && array_key_exists($name, $submitted)) { $attributes['#value'] = $submitted[$name]; } switch ($attributes['#type']) { case "textfield": case "password": $field_html = FormRenderTextField($name, $attributes); break; case "hidden": $value = $attributes['#value']; $field_html .= "<input type=hidden name=\"formfields[{$name}]\" " . "value=\"{$value}\">\n"; break; case "submit": $field_html = FormRenderSubmit($name, $attributes); break; case "image": $field_html = FormRenderImage($name, $attributes); break; case "checkbox": $field_html = FormRenderCheckBox($name, $attributes); break; case "radio": $field_html = FormRenderRadio($name, $attributes); break; case "file": $field_html = FormRenderFile($name, $attributes); break; case "checkboxes": while (list($subname, $subattrs) = each($attributes['#boxes'])) { if ($submitted && array_key_exists($subname, $submitted)) { $subattrs['#value'] = $submitted[$subname]; } $field_html .= FormRenderCheckBox($subname, $subattrs); if (isset($subattrs['#label'])) { $field_html .= $subattrs['#label'] . " "; } } break; case "select": $field_html = FormRenderSelect($name, $attributes); break; case "table": $field_html = FormRenderTable($name, $attributes, $submitted); break; case "list": $field_html = FormRenderList($name, $attributes, $submitted); break; case "vlist": $field_html = FormRenderVList($name, $attributes, $submitted); break; case "textarea": $field_html = FormRenderTextArea($name, $attributes, $submitted); break; case "display": $field_html = isset($submitted[$name]) ? $submitted[$name] : $attributes['#value']; break; } return $field_html; }