PHP Challenged :) - form name array
Posted: Sun Jan 22, 2006 11:04 pm
Ok folks. This one is a CHALLENGE!!! Well for me anyway. I've been modifying an existing form mailing script to suit the needs of my site. I haven't had to mess with the actual processing of the content part on the form processor until I decided to go with an array for the name of a group of check boxes.
Form is being processed as POST. My HTML mixed with PHP for the checkboxes looks something like this. The PHP is for auto-checking already checked fields on error. THIS WORKS!
This is the function that sets up the content to be mailed.
The problem: The form processor (above) isn't setup to handle a NAME as an array as shown in the HTML/PHP mix above, thus when I recieve the message, it simply shows os_version, but doesn't contain data, where it should somehow show that $os_version[dos] == "on"
I'm at a complete loss with how to do this, unless I skip the whole array concept and go with strait names each one being different, but would have to change other code that I'm using that array to check if an item was checked or not. Wouldn't be too much a deal if I had to do that except would be alot more coding to not use an array here as there are actually 17 different OS's as selectable options and will grow with each release of more OS's that will be supported. (make since?)
I just need it to be able to handle an input name as an array within the above parse_form function if possible.
Thanks for any assistance with this as I'm now at a complete loss.
- RJ
Form is being processed as POST. My HTML mixed with PHP for the checkboxes looks something like this. The PHP is for auto-checking already checked fields on error. THIS WORKS!
Code: Select all
<INPUT TYPE="checkbox" NAME="os_version[winxphome]" VALUE="on"
<? if ($formfield['os_version']['winxphome'] == "on")
{
echo " CHECKED ";
}
?>
>This is the function that sets up the content to be mailed.
Code: Select all
// This function takes the sorts, excludes certain keys and
// makes a pretty content string.
function parse_form($array, $sort = "") {
// build reserved keyword array
$reserved_keys[] = "MAX_FILE_SIZE";
$reserved_keys[] = "required";
$reserved_keys[] = "redirect";
$reserved_keys[] = "require";
$reserved_keys[] = "path_to_file";
$reserved_keys[] = "recipient";
$reserved_keys[] = "subject";
$reserved_keys[] = "sort";
$reserved_keys[] = "style_sheet";
$reserved_keys[] = "bgcolor";
$reserved_keys[] = "text_color";
$reserved_keys[] = "link_color";
$reserved_keys[] = "vlink_color";
$reserved_keys[] = "alink_color";
$reserved_keys[] = "title";
$reserved_keys[] = "missing_field_redirect";
$reserved_keys[] = "env_report";
$reserved_keys[] = "submit";
if (count($array)) {
if (is_array($sort)) {
foreach ($sort as $field) {
$reserved_violation = 0;
for ($ri=0; $ri<count($reserved_keys); $ri++)
if ($array[$field] == $reserved_keys[$ri]) $reserved_violation = 1;
if ($reserved_violation != 1) {
if (is_array($array[$field])) {
for ($z=0;$z<count($array[$field]);$z++)
$content .= $field.SEPARATOR.$array[$field][$z].NEWLINE;
} else
$content .= $field.SEPARATOR.$array[$field].NEWLINE;
}
}
}
while (list($key, $val) = each($array)) {
$reserved_violation = 0;
for ($ri=0; $ri<count($reserved_keys); $ri++)
if ($key == $reserved_keys[$ri]) $reserved_violation = 1;
for ($ri=0; $ri<count($sort); $ri++)
if ($key == $sort[$ri]) $reserved_violation = 1;
// prepare content
if ($reserved_violation != 1) {
if (is_array($val)) {
for ($z=0;$z<count($val);$z++)
$content .= $key.SEPARATOR.$val[$z].NEWLINE;
} else
$content .= $key.SEPARATOR.$val.NEWLINE;
}
}
}
return $content;
}I'm at a complete loss with how to do this, unless I skip the whole array concept and go with strait names each one being different, but would have to change other code that I'm using that array to check if an item was checked or not. Wouldn't be too much a deal if I had to do that except would be alot more coding to not use an array here as there are actually 17 different OS's as selectable options and will grow with each release of more OS's that will be supported. (make since?)
I just need it to be able to handle an input name as an array within the above parse_form function if possible.
Thanks for any assistance with this as I'm now at a complete loss.
- RJ