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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.