PHP Scripts for Forms and Interactive Web Sites
PHP can be used without a database to do many things. A database is needed if you are storing information which will be retrieved on later visits (such as text for a webpage or user account information). But for something like a contact form or navigation system where the information will be processed ‘on the fly’ while the user is on the page, no database is necessary. In these cases, PHP can be used to perform calculations, re-route the user to the appropriate page or re-draw the screen based on their choices, or provide data validation to make sure a form was filled out correctly or by a person, not a spambot. The PHP code is incorporated into the existing website to provide specific functions, in combination with the HTML code used to create the pages.
Javascript may be used to do many of the same things. For example, a lot of drop-down menu systems are created with Javascript. PHP can be used to set up a page, or to change things once a user has submitted a form or clicked on a link (this site uses PHP to automatically generate a list of 'Other Pages' in the upper right for each page, based on what section of the site you're in). But if you want changes to happen as the user enters information on a form (not after they've clicked a button), you'll need to use Javascript. The Real Cost of an Employee calculator on this site uses Javascript to perform calculations as the user enters data. The same information could be presented using PHP, but it would require the user to fill out the form and submit it, then would create a new web page showing the completed calculations.
If you've ever filled out a form online and had an alert box pop up because something was entered incorrectly, before you've submitted the form, the form probably uses Javascript. If you've filled out a form and sumitted it, then seen it again with a list of errors, that was probably done with PHP.
The big difference between the two is that Javascript is processed by the user's browser, while PHP is handled by the server. Because of this, a visitor can disable Javascript. They can't do that with PHP, so your scripts should run regardless of how the end user sets up their browser.
Depending on what you want to do and how important it is for scripts to run regardless of your visitor's browser settings, either PHP or Javascript may be a good choice for forms, menus and similar items.
- Forms and Interactive Scripts
- Complete Websites: WordPress and Drupal
- Beyond Websites: Custom Database Systems
