function SetSpecialMultiField($s_name, $i_index, $m_value) { global $SPECIAL_VALUES; // // these special fields cannot be arrays - ignore if it is // if (!is_array($m_value)) { $SPECIAL_VALUES[$s_name][$i_index] = SpecialCleanValue($s_name, $m_value); } }
function ParseInput($a_vars) { global $SPECIAL_FIELDS, $SPECIAL_VALUES, $SPECIAL_MULTI, $FORMATTED_INPUT; $a_order = array(); $a_fields = array(); $a_raw_fields = array(); // // scan the array of values passed in (name-value pairs) and // produce slightly formatted (not HTML) textual output // and extract any special values found. // foreach ($a_vars as $s_name => $raw_value) { $b_special = false; // // split the values into an array of special values and // an array of other values // if (in_array($s_name, $SPECIAL_FIELDS)) { // // special values cannot be arrays; ignore them if they are // if (!is_array($raw_value)) { $SPECIAL_VALUES[$s_name] = SpecialCleanValue($s_name, $raw_value); } $b_special = true; } // // check for multiple values // foreach ($SPECIAL_MULTI as $s_multi_fld) { $i_len = strlen($s_multi_fld); // // look for nameN where N is a number starting from 1 // if (substr($s_name, 0, $i_len) == $s_multi_fld) { $i_index = (int) substr($s_name, $i_len); if ($i_index > 0) { // // re-index to zero // --$i_index; if (!is_array($raw_value)) { // echo "<p>Value '".htmlspecialchars($raw_value)."' is now '". // htmlspecialchars(SpecialCleanValue($s_multi_fld,$raw_value))."'</p>"; $SPECIAL_VALUES[$s_multi_fld][$i_index] = SpecialCleanValue($s_multi_fld, $raw_value); } $b_special = true; break; } } } if (!$b_special) { // // return the raw value unchanged in the $a_raw_fields array // $a_raw_fields[$s_name] = $raw_value; // // handle checkboxes and multiple-selection lists // Thanks go to Theodore Boardman for the suggestion // and initial working code. // if (is_array($raw_value)) { // // the array must be an array of scalars (not an array // of arrays, for example) // if (is_scalar($raw_value[0])) { $a_cleaned_values = CleanValue($raw_value); // // the output is a comma separated list of values for the // checkbox. For example, // events: Diving,Cycling,Running // // Set the clean value to the list of cleaned checkbox // values. // First, remove any commas in the values themselves. // $a_cleaned_values = str_replace(",", "", $a_cleaned_values); $s_cleaned_value = implode(",", $a_cleaned_values); } else { $s_cleaned_value = "<invalid list>"; } } else { // // if the form specifies the "KeepLines" option, // don't strip new lines // if (IsMailOptionSet("KeepLines") && strpos($raw_value, "\n") !== false) { // // truncate first // $s_truncated = substr("{$raw_value}", 0, MAXSTRING); // // split into lines, clean each individual line, // then put it back together again // $a_lines = explode("\n", $s_truncated); $a_lines = CleanValue($a_lines); $s_cleaned_value = implode(BODY_LF, $a_lines); // // and, for this special case, prepend a new line // so that the value is shown on a fresh line // $s_cleaned_value = BODY_LF . $s_cleaned_value; } else { $s_cleaned_value = CleanValue($raw_value); } } // // if the form specifies the "NoEmpty" option, skip // empty values // if (!IsMailOptionSet("NoEmpty") || !empty($s_cleaned_value)) { if (!IsMailExcluded($s_name)) { // // by default, we maintain the order as passed in // the HTTP request // $a_order[] = $s_name; $a_fields[$s_name] = $s_cleaned_value; } } // // add to the $FORMATTED_INPUT array for debugging and // error reporting // array_push($FORMATTED_INPUT, "{$s_name}: '{$s_cleaned_value}'"); } } return array($a_order, $a_fields, $a_raw_fields); }