У меня есть следующий код:
if ( (isset($_GET['slAction'])) && ($_GET['slAction'] == "manage_label") )
{
$formData = getFormData();
foreach ($formData as $key => $value)
echo "(Key: $key, Value: $value )<br /> ";
}
// All form fields are identified by '[id]_[name]', where 'id' is the
// identifier of the form type. Eg. label, store etc.
// The field identifier we want to return is just the name and not the id.
function getFormData()
{
$form_fields = array_keys($_POST);
for ($i = 0; $i < sizeof($form_fields); $i++)
{
$thisField = $form_fields[$i];
$thisValue = $_POST[$thisField];
//If field is an array, put all it's values into one string
if (is_array($thisValue))
{
for ($j = 0; $j < sizeof($thisValue); $j++)
{
$str .= "$thisValue[$j],";
}
// Remove the extra ',' at the end
$thisValue = substr($str, 0, -1);
//Assosiative array $variable[key] = value
$formData[end(explode("_", $thisField))] = $thisValue;
}
else
$formData[end(explode("_", $thisField))] = $thisValue;
}
return $formData;
}
Выходные данные этого кода:
(Key: id, Value: 7276 )
(Key: name, Value: 911 Main brand )
(Key: email, Value: )
(Key: www, Value: )
(Key: categories, Value: Menswear,Womenswear,Shoes )
(Key: targetgroup, Value: )
(Key: keywords, Value: )
(Key: description, Value: Testing )
(Key: saveForm, Value: Save )
Теперь это моя проблема . Поле формы с именем label_categories является флажками и возвращается в виде массива. Выход, как вы видите, «Мужская одежда, Женская одежда, Обувь».
Если я попробую 'echo $ formData [' name ']', вы получите «911 Main brand».
Если я попробую 'echo $ formData [' category ']. вывод пуст / пуст.
Почему я могу вывести строку «имя», а не строку «категории»? В функции getFormData () я превращаю массив в строку ....
Любая помощь приветствуется.