There is a form with an unknown number of inputs of the form.

input type="text" name="order[inputname]" 

What should I write in the php file of the form handler so that the contents of all inputs are embedded in the body of the letter and sent to the specified address.

  • Can foreach loop? foreach($_POST as $key => $value) { ... } - RussCoder
  • Why it does not work. Where is the mistake? $ text = ""; foreach ($ _ POST as $ key => $ val) {$ text = $ text. $ key. $ val. "<br>"; } ' - mxd
  • one
    And what comes if you write in a loop? Instead of <br/> probably need \r\n and the loop is some kind of untrue .. when the name is order[inputname] then each value truncates the previous one ... if there are many inputs with that name ..... better show all the html and how and what do you do in php ......... most likely you need a cycle of $_POST['order'] - Alexey Shimansky
  • The letter comes formArray <br> - mxd
  • one
    well, OK. A console and Network'om you also do not know how to use? ... they also write there in black and white what form[Name]:asd form[Subject]:123 form[Send]:Отправить form[formId]:4 sent form[Name]:asd form[Subject]:123 form[Send]:Отправить form[formId]:4 ..... respectively, and the loop will be foreach($_POST['form'] as $key=>$val) { ..... ... and it is better to remove the Subject field from the post request ..... learn how to use the developer tools - Alexey Shimansky

1 answer 1

 <input type="text" name="order[]" > $text = ''; foreach ($_POST['order'] as $key => $value) { if ($value != null) $text.= $value; } echo $text; 
  • In the answers it is customary to give an explanation, not just the code. - AivanF.
  • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky