Presentation is loading. Please wait.

Presentation is loading. Please wait.

>> PHP: Form-Variables & Submission

Similar presentations


Presentation on theme: ">> PHP: Form-Variables & Submission"— Presentation transcript:

1 >> PHP: Form-Variables & Submission

2 Form Submission <form > </form> id=“ “ name=“ “ action=“ “
method=“ “ For form identification File/function to call Method to submit the form GET | POST <form name=“contact” action=“process.php” method=“GET”> 1. contact.html 2. return contact.html 3. Fill form 4. process.php (values) 6. HTML File 5. Run process.php

3 GET Method Sends the form information by including it on the URL
process.php?name=……& =……&content=…… When to use Short forms, with only 1 or 2 input fields Forms with select, radio, and checkbox fields

4 Google Maps Graduation Party maps.google.com/maps?saddr=……&daddr=……. You are invited!!!!!!!! Please Please come If unable to find, enter your address below and I will guide you Maps with directions Guide Me <form action=" method="get" target="_blank"> If unable to find, enter your address below and I will guide you <input type="text" name="saddr" /> <input type="hidden" name="daddr" value=“King Faisal University" /> <input type="submit" value=“Guide Me" /> </form>

5 Google Maps

6 POST Method Sends the data to the server in two steps
Browser contacts the server Send the information When to use Longer forms, more than 3 input fields Forms with large textarea fields Forms where security is more important

7 Some Guidelines Always assign a name attribute to your form fields
Eg. <input type=“text” name=“username”/> Remember Associative Arrays name=“username” => What the user enters Key Value How will you access this information in PHP Create a variable Use the associative array technique Index is the key name What is the array-name? Based on the method used $uname = array-name ‘username’ $_GET | $_POST

8 All Pre-defined Form Variables
$_GET variable can be used to collect form data sent with the GET method. $_POST variable can be used to collect form data sent with the POST method. $_REQUEST variable can be used to collect form data sent with both the GET and POST methods. $varName = $_GET[‘username’]; $varName = $_POST[‘username’]; $varName = $_REQUEST[‘username’];

9 Back to Mini Project Our Old Files Go Online index.php header.php
footer.php contact.php stuff.php Go Online Download the add-item.php file Copy in the same folder (D:\xampp\htdocs\Buy4mMe\) Now open the project in Aptana/NetBeans

10 Processing File TRY NOW TRY NOW Will this work?
Create a new file called add-process.php Open the file and accept the submitted values from the form (using the $_POST variable) Write Insert Query to add the item to the database TRY NOW Will this work? Open the add-item.php file Go down to the form tag Add the attributes method action TRY NOW


Download ppt ">> PHP: Form-Variables & Submission"

Similar presentations


Ads by Google