I have a dropdown and a checkbox within a form, the user needs to be able to select a value of the dropdown, and checkbox value(s) which are added to the database, but also show these values the next time the user visits the form.
Here's the code
The response will be whether a level is selected (1-5), if not then leave blank. If it is, they can also select which values within that level are applicable. So a typical response will be
1, a, b, c
I need to enter this into the database column as 1a,1b,1c.
When coming back to the page, the form needs to see which number they previously selected and select it in the dropdown, and tick the correct a-h checkboxes.
Before I start to enter into the database, on submit I wanted to get the format of the response correct so tried
But I just get back 'Array'.
I then tried to implode it
expecting something like 1,a,b,c (not quite what I want as I'd want 1a,1b,1c) but still just get 'Array'.
Can someone help please?
Thanks
Here's the code
Code:
<select name=‘whatlevels[]’>
<option value=''>No</option>
<option value='1' <?php if ($row['whatlevels'] == '1') { echo 'selected="selected"'; } ?>>1</option>
<option value='2' <?php if ($row['whatlevels'] == '2') { echo 'selected="selected"'; } ?>>2</option>
<option value='3' <?php if ($row['whatlevels'] == '3') { echo 'selected="selected"'; } ?>>3</option>
<option value='4' <?php if ($row['whatlevels'] == '4') { echo 'selected="selected"'; } ?>>4</option>
<option value='5' <?php if ($row['whatlevels'] == '5') { echo 'selected="selected"'; } ?>>5</option>
</select>
<span>
<label for='level_a'>a</label> <input type='checkbox' name='whatlevels[]' id='level_a' value='a' />
<label for='level_b'>b</label> <input type='checkbox' name='whatlevels[]' id='level_b' value='b' />
<label for='level_c'>c</label> <input type='checkbox' name='whatlevels[]' id='level_c' value='c' />
<label for='level_d'>d</label> <input type='checkbox' name='whatlevels[]' id='level_d' value='d' />
<label for='level_e'>e</label> <input type='checkbox' name='whatlevels[]' id='level_e' value='e' />
<label for='level_f'>f</label> <input type='checkbox' name='whatlevels[]' id='level_f' value='f' />
<label for='level_g'>g</label> <input type='checkbox' name='whatlevels[]' id='level_g' value='g' />
<label for='level_h'>h</label> <input type='checkbox' name='whatlevels[]' id='level_h' value='h' />
</span>
The response will be whether a level is selected (1-5), if not then leave blank. If it is, they can also select which values within that level are applicable. So a typical response will be
1, a, b, c
I need to enter this into the database column as 1a,1b,1c.
When coming back to the page, the form needs to see which number they previously selected and select it in the dropdown, and tick the correct a-h checkboxes.
Before I start to enter into the database, on submit I wanted to get the format of the response correct so tried
Code:
echo $_POST['whatlevels'];
But I just get back 'Array'.
I then tried to implode it
Code:
echo implode(',', $_POST['whatlevels']);
expecting something like 1,a,b,c (not quite what I want as I'd want 1a,1b,1c) but still just get 'Array'.
Can someone help please?
Thanks