Passing Data from JavaScript to PHP

In the role of a confirmation tool, JavaScript can check the content of forms before data is sent to a PHP script. Such a role is important for real-world forms because, if troublesome data are sent to a PHP script, the wrong data could end up in your database.

PHP recognizes data from an HTML form element using the same naming structure, but with the added dollar sign before the variable name. For example, if a form element is named this:

						alpha 

in an HTML page, it will be recognized as this in a PHP script:

						$alpha 

To see one role of JavaScript in gathering in information, these next two scripts, one an HTML page and the other a PHP script, show how data can originate in

JavaScript and be passed to PHP. ...

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.