|
Posted by larry on 09/09/07 02:40
Keep in mind if no boxes are checked you don't get the value passed
back. Following are a couple functions I put together to retain my
sanity in checklists and other array input use it like:
$arrayname = postarrayfix('postarrayname');
It strips out any potentially bad HTML and slashes if magic quotes are
on.
/*$_POST Fixer, if the following lists are empty, the POSTs return
nulls, which is bad, as the code needs arrays (even empty) to display,
this fixes it.*/
function postArrayFix($postname){
if( empty($_POST[$postname]) ){
$value = array();
} else {
$value = cleanArray($_POST[$postname]);
}
return $value;
}
/*This one is for if you are reading in arrays from $_POST data, it
will walk deep into the array and clean it up.
*/
function cleanArray($value)
{
if(get_magic_quotes_gpc()) {
$value = is_array($value) ?
array_map('cleanArray', $value) :
stripslashes(strip_tags($value));
} else {
$value = is_array($value) ?
array_map('cleanArray', $value) :
strip_tags($value);
}
return $value;
}
[Back to original message]
|