0

Currently I am creating a dynamic site that uses check boxes to gather information. The problem is, when the value of a checkbox contains a comma, the remaining text after the "," is dropped from the array.

In Essence:

if (isset($_POST['team_members'])){
        $team_members = $_POST['team_members'];
        if (is_array($team_members)){
        $team_members = implode("|", $team_members);
        }

team_members data includes:

<input type="Checkbox" name="team_members[]" value="Company Name 1">
<input type="Checkbox" name="team_members[]" value="Company Name 2">
<input type="Checkbox" name="team_members[]" value="Company Name 3, Inc.">
<input type="Checkbox" name="team_members[]" value="Company Name 4, LLC.">

Let's say that I chose [0] and [1], $team_members becomes: "Company Name 1|Company Name 2"

If I chose [0] and [2] $team_members becomes: "Company Name 1|Company Name 3,"

Any help will be appreciated.

edit: Array ( [0] => Accenture [1] => Alion [2] => CACI [3] => Deloitte, ) It appears it is also removing things by "space" and not ","...

Badwolf
  • 9
  • 2
  • Right below `if (isset($_POST['team_members'])){`, do `print_r($_POST['team_members'])`, and post the output please. – Blue Jan 17 '18 at 20:27
  • are you sure [2] posted completely ? echo [2] and make sure its print `'Company Name 3, Inc.'` – aidinMC Jan 17 '18 at 20:28
  • Is this being submitted by standard form submit of type post? Not any javascript meddling in the works? – IncredibleHat Jan 17 '18 at 20:28
  • Array ( [0] => Accenture [1] => Alion [2] => CACI [3] => Deloitte, ) – Badwolf Jan 17 '18 at 20:40
  • Are your values _actually_ quoted in your code? They are in your post. Seems like this error: https://stackoverflow.com/questions/29901488/html-input-form-box-not-populating-php-value-after-first-space Your question may be closed as "Off-topic: Why isn't my code working..." if you do not reply to all requests for additional details. – mickmackusa Jan 17 '18 at 20:43
  • " . $row3["company"]; – Badwolf Jan 17 '18 at 20:46
  • Yup, improper quoting. This is a duplicate. Next time you ask a question, copy paste your real code so that everything is clear and accurate for us. – mickmackusa Jan 17 '18 at 20:48
  • Can I use a mixture of " and ' when im quoting withing a quote? – Badwolf Jan 17 '18 at 20:51
  • Yes or `\"` to escape double quotes – mickmackusa Jan 17 '18 at 20:53
  • echo "" . $row3["company"]; Should look like this? echo "" . $row3["company"]; ? – Badwolf Jan 17 '18 at 20:56
  • ok got it. thanks! You guys are awesome! – Badwolf Jan 17 '18 at 20:58
  • Possible duplicate of [HTML input form box not populating PHP value after first space](https://stackoverflow.com/questions/29901488/html-input-form-box-not-populating-php-value-after-first-space) – mickmackusa Jan 17 '18 at 21:02
  • Yeah, that seems to be the issue. I just cant find a way to place value in quotations without breaking the php output code... – Badwolf Jan 17 '18 at 21:05
  • https://stackoverflow.com/a/33526632/2943403 – mickmackusa Jan 17 '18 at 22:38

0 Answers0