function check_length_fields($POST, $fields_labels_ar){
$i =0;
$check = 1;
$count_temp = count($fields_labels_ar);
while ($i<$count_temp and $check == 1){
$field_name_temp = $fields_labels_ar[$i]["name_field"];
// I use isset for select_multiple because could be unset
if ($fields_labels_ar[$i]["maxlength_field"] != "" && isset($POST[$field_name_temp])){
switch($fields_labels_ar[$i]["type_field"]){
case "text":
case "password":
case "textarea":
if (strlen($POST[$field_name_temp]) > $fields_labels_ar[$i]["maxlength_field"]){
$check = 0;
} // end if
break;
case "select_multiple_checkbox":
case "select_multiple_menu":
$count_temp_2 = count($POST[$field_name_temp]);
$value_temp = "";
for ($j=0; $j<$count_temp_2; $j++) {
$value_temp .= $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_temp][$j];
}
$value_temp .= $fields_labels_ar[$i]["separator_field"]; // add the last separator
if (strlen($value_temp) > $fields_labels_ar[$i]["maxlength_field"]){
$check = 0;
} // end if
break;
case "select_single":
if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......"){
$field_name_other_temp = $field_name_temp."_other____";
if (strlen($_POST[$field_name_other_temp]) > $fields_labels_ar[$i]["maxlength_field"]){
$check = 0;
} // end if
} // end if
else{
if (strlen($_POST[$field_name_temp]) > $fields_labels_ar[$i]["maxlength_field"]){
$check = 0;
} // end if
} // end else
break;
} // end switch
} // end if
$i++;
} // end while
return $check;
} // end function check_length_fields
I use the above function to check the length of fields after they are posted. It works fine unless someone enters the maximum length of characters and one of those characters is a quote. This quote forces magic quotes to add a slash, making the field length one bigger. An error is returned to the user "too much text in field". What is the best solution to this situation, I dont want to turn off magic quotes. I guess i could remove the quotes, or ask the user not to use them, etc...
Thanks