In my code I read items from a table and populate a form with x number of items using checkbox inputs. When the submit button is selected it submits the items_selected[] array with the items that were checked.
This all works. My problem is when the items read and displayed in the form contain a single quote. The array only returns the string up to the quote in the string. I’m assuming I’ll have the same problem with any of the characters that need to be “escaped” but I can’t seem to figure out how to do it.
Any help would be appreciated.
Below is a somewhat stripped down version of the code
<form action="" method="post">
<?php foreach ($items as $item): ?>
<label class="cbcontainer">
<?php echo "<input type='checkbox' name='items_selected[]' value='{$item['item_name']}' >"
. ' <b>' . $item['item_name'] . ')'; ?>
<span class="cbcheckmark"></span>
</label>
<?php endforeach ?>
<?php if($formSubmitBtn === false): ?>
<div style="margin: 0px 210px 20px; text-align:left;">
<button type="submit" name="updateVotesBtn" class="btn btn-primary">Submit</button>
</div>
<?php $formSubmitBtn = true; ?>
<?php endif ?>
</form>
<?php
/*
If the form was populated with
This is an entry
This is entry can't be passed properly
This is another entry
The items post array looks like the following:
Array
(
[items_selected] => Array
(
[0] => This is an entry
[1] => This is entry can --***** HERE'S the problem ***
[2] => This is another entry
)
[updateVotesBtn] =>
)
*/