Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > PHP Forum & Tutorial


PHP Forms and User Input


Reply
Views: 2351  
Thread Tools Rate Thread
  #1  
Old 05-04-2009, 05:01 PM
welcomewiki welcomewiki is offline
Member
 
Join Date: Dec 2008
Location: India
Posts: 80,538
Default PHP Forms and User Input

The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.



PHP Form Handling

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.




Form example:





Name:
Age:






The example HTML page above contains two input fields and a submit ****on. When the user fills in this form and click on the submit ****on, the form data is sent to the "welcome.php" file.




The "welcome.php" file looks like this:





Welcome .

You are years old.




A sample output of the above script may be:




Welcome John.
You are 28 years old.



The PHP $_GET and $_POST variables will be explained in the next chapters.
Form Validation

User input should be validated whenever possible. Client side validation is faster, and will reduce server load.



However, any site that gets enough traffic to worry about server resources, may also need to worry about site security. You should always use server side validation if the form accesses a database.


A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.

Reply With Quote
Reply

New topics in PHP Forum & Tutorial





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)