arrays - php form with multiple item checkbox populate excel spreadsheet -
i building form in php send owner email request , link page table show requests. keep getting "array" in output multiple item checklist... here have
<form> <input type="checkbox" name="multimedia[]" value="assessment" />assessment<br/> <input type="checkbox" name="multimedia[]" value="elearning module" />e-learning module<br /> <input type="checkbox" name="multimedia[]" value="photography" />photography<br />
video shoot
other
<?php $multimedia = array(); echo implode(',', $_post['multimedia']); $multimedia_string = implode(',', $multimedia); ?> //variables in each cell $variables = array(); $variables['fname'] = $_post['fname']; $variables['lname'] = $_post['lname']; $variables['email'] = $_post['email']; $variables['projecttitle'] = $_post['projecttitle']; $variables['$multimedia_string'] = $_post['$multimedia_string']; $variables['credentialing'] = $_post['credentialing']; $variables['description'] = $_post['description']; $variables['results_data_page'] = $results_data_page;
change this:
$variables['$multimedia_string'] = $_post['$multimedia_string'];
...to:
$variables['multimedia_string'] = implode(',', $_post['multimedia']);
explanation:
php interprets $_post['multimedia']
array due having square brackets []
after name, in multimedia[]
, can implode using comma separator , string returned.
there other issues, try instead:
<?php //variables in each cell $variables = array(); $variables['fname'] = $_post['fname']; $variables['lname'] = $_post['lname']; $variables['email'] = $_post['email']; $variables['projecttitle'] = $_post['projecttitle']; $variables['multimedia_string'] = implode(',', $_post['multimedia']); $variables['credentialing'] = $_post['credentialing']; $variables['description'] = $_post['description']; $variables['results_data_page'] = $results_data_page; ?>
issues:
the first 3 lines don't seem anything.
$multimedia = array(); // never populated echo implode(',', $_post['multimedia']); $multimedia_string = implode(',', $multimedia); // still not populated, implodes empty string.
a couple things here:
$variables['$multimedia_string'] = $_post['$multimedia_string'];
php variables not interpolated in single quoted string. in other words, translate php variables variable name $name
value, in string, need use either double quotes or heredoc:
echo "i $emotion much."; $html = <<<eot <table> <tr> <td>we $emotion camping.</td> </tr> </table> eot;
so '$multimedia_string'
string containing dollar sign , text "multimedia_string".
the other thing appears there no $_post
var name or whatever intended $multimedia_string
translate to.
Comments
Post a Comment