Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,

Similar presentations


Presentation on theme: "Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,"— Presentation transcript:

1 Unit 4 Working with data

2 Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, text area, field set and label elements. The tag is used to create an HTML form:

3 . input elements.

4 Input Element The most important form element is the input element. The input element is used to select user information. An input element can be different in many ways, depending on the type attribute. An input element can be of type text field, checkbox, password, radio button, submit button, and more. The most used input types are described below.

5 1. Text Fields defines a one-line input field that a user can enter text into: First name: Last name: Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.

6 2. Password Field defines a password field: E.X:- Password: Note: The characters in a password field are masked (shown as asterisks or circles).

7 3. Radio Buttons defines a radio button. Radio buttons let a user select ONLY ONE one of a limited number of choices: Male Female

8 4. Checkboxes defines a checkbox. Checkboxes let a user select ONE or MORE options of a limited number of choices. I have a bike I have a car

9 5. Submit Button defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input: Username:

10 6. Select (Pull Down menu) and Select multiple HTML form element This type of HTML form element is used to allow user to select from multiple choices. For example selecting a month or a day. The html syntax is as below. 2004 2005 2006 2007 2008

11 7. Hidden defines a hidden field. A hidden field is not visible for the user. Hidden fields often store a default value, or have their value changed by a JavaScript. Example:-

12 7. Image defines an image as a submit button. The src and alt attribute are required with. Example:-

13 Passing variables between pages 1.Passing variable through a GET $_GET Function:- The built-in $_GET function is used to collect values in a form 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.

14 Example 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?fna me=Peter&age=37

15 Welcome ! You are years old.

16 The "welcome.php" file can now use the $_GET function to collect form data. When using method="get" in HTML forms, all variable names and values are displayed in the URL Note: 1. This method should not be used when sending passwords or other sensitive information! 2. The get method is not suitable for very large variable values. It should not be used with values exceeding 2000 characters.

17 2. Passing variable through a POST:- 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).

18 Example Name: Age: When the user clicks the "Submit" button, the URL will look like this: http://www.w3schools.com/welcome.php

19 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): E.X:- Welcome ! You are years old. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

20 3. Passing variable through a REQUEST:- 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.

21 Example:- Firstname: Lastname: ; echo “Lastname: “ $_REQUEST[“lastname”]; ?>

22 Validating the user input "never trust user input" is the golden rule on the web. There are several types of problem that’s why we need the validation on user input. Problems like 1. Mistake on input. User types 1095 rather than 10.95 2. Bad input. User purposefully provides incorrect input in attempt to gain advantage 3. Dangerous input. User innocently enters information that would harm the system 4. Missing input. User provides no input.

23 When validating input, we have two choices: 1.validate on the client side using a scripting language. 2. validate on the server side using PHP.

24 1. Client side Validation using a scripting language You can write scripting code that will verify form fields contain good data before being submitted to the server, and this is often used. The advantages to using client-side validation are: 1.users receive feedback quicker 2.it saves load on the server - more work is done on the client side.

25 The disadvantage to using client-side validation are: 1. client-side support for varies scripting languages, with some browsers supporting scripts very well, others supporting bits and pieces, and others supporting nothing at all. 2. Furthermore, clever users can disable your client-side checking in order to feed you bad data - if you only apply client-side checking, you are bound to get hacked eventually.

26 Server side validate using PHP. Server-side data validation means using PHP to verify that good values have been sent to the script. Using server-side validation has pretty much the exact opposite of client-side development: it is more secure and works with all browsers, but it is costly and slower feedback for users.

27 One big advantage to server-side validation is that you can use PHP - a language by now you have attained some skill with. As you know, PHP has a wide variety of functions and language features to help you cut and change strings, check numbers are within ranges, and so on. Furthermore, you can use PHP to connect to a database to check whether a username exists, for example, which is simply impossible using client-side scripting.


Download ppt "Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,"

Similar presentations


Ads by Google