0

I have two fields (at minimum) that both have the same name attribute. Using a little jQuery, the user can add more text boxes using jQuery's .clone() feature. Every possible input they add will have the same name attribute as the first two. I want to try to use php to create a comma separated list of every input value after the form is submitted.

$competitor_names = $_POST['competitor-name'];
$competitorList = '';
foreach($competitor_names as $competitorList) {
    $competitorList = $competitorList.', ';
}
user3813156
  • 43
  • 1
  • 10
  • Form input arrays, have a look at this: https://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array – stewo Jul 27 '17 at 21:48
  • Try `$competitorList = implode(', ',$competitor_names);` – Yolo Jul 27 '17 at 21:50
  • You use $competitorList for two different things. Probably you want to rename one of them. – jh1711 Jul 27 '17 at 21:50

1 Answers1

1

The function implode() seems to be what you're looking for :

$competitor_names = $_POST['competitor-name'];
$competitorList = implode(',', $competitor_names);
micster
  • 758
  • 3
  • 10