Download presentation
Presentation is loading. Please wait.
Published byHolly Marshall Modified over 9 years ago
2
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method keyword – One or more input elements defined with the input tag – The destination to go to when submitted defined with the action keyword
3
How to use PHP and web forms to carry out the following tasks: Pass data from a form to a PHP script Validate form data Work with multivalued form components
4
PHP offers a number of useful predefined variables that are accessible from anywhere within the executing script and provide you with a substantial amount of environment- specific information. You can sift through these variables to retrieve details about the current user session, the user’s operating environment, the local operating environment
5
There are two common methods for passing data from one script to another: GET and POST. Although GET is the default, you’ll typically want to use POST because it’s capable of handling considerably more data, an important characteristic when you’re using forms to insert and modify large blocks of text. If you use POST, any posted data sent to a PHP script must be referenced using the $_POST
6
The built-in $_GET function is used to collect values from a form sent with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
7
– Name: Age: When the user clicks the "Submit" button, the URL sent to the server could look something like this: – http://www.w3schools.com/welcome.php?fname=Peter&age= 37 The "welcome.php" file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): – Welcome. You are years old!
8
The built-in $_POST function is used to collect values from a form sent with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).
9
– Name: Age: When the user clicks the "Submit" button, the URL will look like this: http://www.w3schools.com/welcome.php The "welcome.php" file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): – Welcome ! You are years old.
10
The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST, and $_COOKIE. The $_REQUEST function can be used to collect form data sent with both the GET and POST methods. Example – Welcome ! You are years old.
11
The following script renders a form that prompts the user for his name and e-mail address. Once completed and submitted, the script (named subscribe.php) displays this information back to the browser window
14
<?php $input = "I really love PHP !"; $input = strip_tags($input," "); // $input now equals "I really love PHP !" ?>
15
$email = "john@@example.com"; if (! filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "INVALID E-MAIL!"; }
17
It’s also possible to use the Filter component to sanitize data, which can be useful when processing user input intended to be posted in a forum or blog comments. For instance, to remove all tags from a string, you can use the FILTER_SANITIZE_STRING: – $userInput = "Love the site. E-mail me at Spammer."; – $sanitizedInput = filter_var($userInput, FILTER_SANITIZE_STRING); – // $sanitizedInput = Love the site. E-mail me at Spammer. Table 13-2. The Filter Extension’s Sanitization Capabilities, pg-295
19
Text Box Check box Radio button Hidden Select
20
1. Feet to Meter Converter 2. Time Zone converter
21
Some time we have to check the existence of a variable before using it for our further processing. The variable can be checked by using PHP isset function and the return value will be either true or false. – Here is an example The htmlentities() function converts characters to HTML entities. The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.