HTML JS

DISPLAY MESSAGE AFTER SUBMITTING HTML FORM

USE JAVASCRIPT TO SUBMIT FORM <form id="myForm"             onsubmit="return ajaxpost()">   <input type="text" name="name" />   <input type="email" name="email"/>   <input type="submit" value="Go!"/> </form>

AJAX POST PART A

01

function ajaxpost () {   GET FORM DATA   var form = document.     getElementById("myForm");   var data = new FormData(form);

AJAX POST PART B

02

  AJAX POST   fetch(URL", {     method:"POST", body:data    }).then(res=>res.text())

  SHOW MESSAGE ON RESPONSE   .then((res) => { alert(res); }); }

SERVER MESSAGE PART A

03

PROCESS & SHOW MESSAGE <?php  if (isset($_POST["name"])) {        require "PROCESS.PHP";        echo "<div>$message</div>"; } ?>

SUBMIT TO SAME PAGE <form method="post" target="_self">   <input type="text" name="name" />   <input type="email" name="email"/>   <input type="submit" value="Go!"/> </form>

DO WHATEVER PROCESSING REQUIRED. SAVE TO DATABASE, SEND EMAIL, ETC...   FINALLY, SET A SYSTEM MESSAGE $message = "OK"; $message = "ERROR!";

SERVER MESSAGE PART B

04