So, I'm having trouble figuring this one out. I populate a select box with values from Excel, and give the select box the name of the worksheet.
function populateDropDown($excelSheet) {
$objPHPExcel = PHPExcel_IOFactory::load($excelSheet, $num);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
echo '<select name= ' . $worksheetTitle . '>';
for ($row = 1; $row <= $highestRow; ++ $row) {
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
if ($col == 0) {
$id = $cell->getValue();
} else if ($col == 1) {
$val = $cell->getValue();
}
}
echo '<option value=' . $id . '>';
echo $val;
echo '</option>';
}
echo '</select>';
}
return $worksheetTitle;
}
At the end of this function, I return the title and it is stored into a variable on the form page.
<?php $selectBox1 = populateDropDown("workbook1.xlsx"); ?>
When the form is submitted, how can I get the data of this variable? I've tried the following without it working:
$var = $_POST[$selectBox1];
$var = $_POST['$selectBox1'];
$var = $selectBox1;
Hardcoding the sheet name works, however:
$var = $_POST['Sheet1'];
So, I'm positive it's a problem with the variable. I'm sorry if this has been asked before, I searched for quite some time but didn't find anything that helped. Thank you for any help!
Again, just to clarify my question, how can I use $_POST to get the data from the select box, when the name of the select box was named with a variable?
Edit: added entirety of populateDropDown function
populateDropDownobviously some framework we are not seeing herepopulateDropDownis a custom function from which the first 3 lines of code are taken. I think a more through description of what you're doing is necessary. Could you post the complete form code? I think you may have forgotten to make theformsubmission methodPOST.