Our References

Step 4: Handling User Input After a user submits our form, we want to grab their input and write it to our chat log. In order to do this, we must use jQuery and PHP to work synchronously on the client and server sides. jQuery Almost everything we are going to do with jQuery to handle our data will revolve around the jQuery post request. //If user submits the form $("#submitmsg").click(function () { var clientmsg = $("#usermsg").val(); $.post("post.php", { text: clientmsg }); $("#usermsg").val(""); return false; }); Before we do anything, we must grab the user's input, or what the user has typed into the #submitmsg input. This can be achieved with the val() function, which gets the value set in a form field. We now store this value in the clientmsg variable. Here comes our most important part: the jQuery post request. This sends a POST request to the post.php file that we will create in a moment. It posts the client's input, or what has been saved into the clientmsg variable. Lastly, we clear the #usermsg input by setting the value attribute to blank. Please note that the code above will go into our script tag, where we placed the jQuery logout code. PHP: The post.php File At the moment, we have POST data being sent to the post.php file each time the user submits the form and sends a new message. Our goal now is to grab this data and write it into our chat log.