JavaScript Form Preprocessing for PHP

Now that the concept of JavaScript’s role with PHP is clear, it is time to do something more practical with JavaScript and PHP. This next set of scripts uses JavaScript as a preprocessor to make sure that a comment form being sent has all of the forms filled out and that the user remembers to include an “@” sign in her email address. The JavaScript also shows how to combine two functions into a single function that performs two tasks.

Before starting, you need to know a PHP function not yet discussed. The function mail(e,s,m,h) has four arguments:

  • e Email address

  • s Subject

  • m Message

  • h Header

Each of the arguments can be set as variables or strings in quotation marks. For example, this line would fire off ...

Get JavaScript Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.