Hi guys. I have the following code:
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;
}
The output from this code is:
(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 )
Now this is my problem. The form field called 'label_categories' are checkboxes and is returned as an array. The output, as you see, is "Menswear,Womenswear,Shoes". If I try 'echo $formData['name']', the output is "911 Main brand". If I try 'echo $formData['categories']. the output is blank / empty.
How come I can output the string 'name' and not the string 'categories'? In the getFormData() function, I turn the array into a string....
Any help appreciated.