#
$formfields["nsfile"] = "";
if (isset($formfields["guid"])) {
    if ($formfields["guid"] == "" || !preg_match("/^\\d+\$/", $formfields["guid"])) {
        $errors["NS File GUID"] = "Invalid characters";
    }
    $nsfilelocale = "nsref";
} elseif (isset($formfields["nsref"])) {
    if ($formfields["nsref"] == "" || !preg_match("/^\\d+\$/", $formfields["nsref"])) {
        $errors["NS File Reference"] = "Invalid characters";
    }
    $nsfilelocale = "nsref";
} elseif (isset($formfields["localnsfile"]) && $formfields["localnsfile"] != "") {
    if (!preg_match("/^([-\\@\\w\\.\\/]+)\$/", $formfields["localnsfile"])) {
        $errors["Server NS File"] = "Pathname includes illegal characters";
    } elseif (!VALIDUSERPATH($formfields["localnsfile"])) {
        $errors["Server NS File"] = "Must reside in one of: {$TBVALIDDIRS}";
    }
    $nsfilelocale = "local";
} elseif (isset($_FILES['nsfile']) && $_FILES['nsfile']['size'] != 0) {
    if ($_FILES['nsfile']['size'] > 1024 * 500) {
        $errors["Local NS File"] = "Too big!";
    } elseif ($_FILES['nsfile']['name'] == "") {
        $errors["Local NS File"] = "Local filename does not appear to be valid";
    } elseif ($_FILES['nsfile']['tmp_name'] == "") {
        $errors["Local NS File"] = "Temp filename does not appear to be valid";
    } elseif (!preg_match("/^([-\\@\\w\\.\\/]+)\$/", $_FILES['nsfile']['tmp_name'])) {
        $errors["Local NS File"] = "Temp path includes illegal characters";
    }
    #
    # For the benefit of the form. Remember to pass back actual filename, not
    if (!TBvalid_template_description($formfields["description"])) {
        $errors["Description"] = TBFieldErrorString();
    } else {
        $command_options .= " -E " . escapeshellarg($formfields["description"]);
    }
}
#
# Parameters. The XML file overrides stuff in the form.
#
$template->FormalParameters($parameter_masterlist);
if (count($parameter_masterlist)) {
    if (isset($formfields["parameter_xmlfile"]) && $formfields["parameter_xmlfile"] != "") {
        $parameter_xmlfile = $formfields["parameter_xmlfile"];
        if (!preg_match("/^([-\\@\\w\\.\\/]+)\$/", $parameter_xmlfile)) {
            $errors["Parameter XML File"] = "Pathname includes illegal characters";
        } elseif (!VALIDUSERPATH($parameter_xmlfile)) {
            $errors["Parameter XML File"] = "Must reside in one of: {$TBVALIDDIRS}";
        }
        $deletexmlfile = 0;
    } else {
        #
        # Lets confirm that the user did not forget to set at least one value.
        #
        $gotone = 0;
        while (list($name, $default_value) = each($parameter_masterlist)) {
            if (isset($parameters[$name]) && $parameters[$name] != "") {
                $gotone = 1;
            }
        }
        if (!$gotone) {
            $errors["Parameters"] = "You did not set any values";