HTML PHP

HOW TO POST ARRAY FROM HTML FORM TO PHP

APPEND [] TO NAME <form method="post">   <input type="text" name="colors[]"/>    <input type="text" name="colors[]"/>    <input type="submit" value="GO"/> </form>

$_POST["COLORS"] IS AN ARRAY print_r($_POST["colors"]);

SEND SIMPLE ARRAY

01

APPEND [KEY][] TO NAME <form method="post">   <label>Colors</label>   <input type="text" name="fav[c][]"/>    <input type="text" name="fav[c][]"/>

SEND NESTED ARRAY

02

  <label>Food</label>   <input type="text" name="fav[f][]"/>   <input type="text" name="fav[f][]"/>      <input type="submit" value="GO"/> </form>

<form method="post" id="myForm"             onsubmit="return ajax()">   <label>Colors</label>   <input type="text" name="fav[c][]"/>    <input type="text" name="fav[c][]"/>

AJAX SEND ARRAY (A)

03

  <label>Food</label>   <input type="text" name="fav[f][]"/>   <input type="text" name="fav[f][]"/>      <input type="submit" value="GO"/> </form>

function ajax () {   GET FORM DATA   var data = new FormData(document   .getElementById("myForm"));     AJAX SEND   fetch("SCRIPT.PHP", { method:"POST",    body:data }); }

AJAX SEND ARRAY (B)

04