HTML Forms Validation CS360 Javascript. On to forms processing... The processing of a form is done in two parts: –Client-side at the browser, before the.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Tutorial 6 Creating a Web Form
1 Topic 6 Processing Form Input. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction Form.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
Lesson 3 HTML Forms Handling. the Form object Tag : Properties: –action - action attribute of tag –elements[ ] - creeated from like named form elements.
JavaScript Forms Form Validation Cookies CGI Programs.
Forms Describe common uses of forms on web pages
Advanced Javascript Dick Steflik Binghamton University.
Tutorial 14 Working with Forms and Regular Expressions.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
1 More JavaScript, HTML Forms, CGI Scripts Tom Horton Alfred C. Weaver CS453 Electronic Commerce.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
JavaScript Form Validation
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Tutorial 14 Working with Forms and Regular Expressions.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Project Four Forms Discuss form processing Describe the difference between client-side and server-side form processing Add a horizontal rule to a Web page.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Website Development with PHP and MySQL Saving Data.
HTML Forms.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
ITCS373: Internet Technology Lecture 5: More HTML.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Introduction to JavaScript CS101 Introduction to Computing.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Web Technologies Lecture 3 Web forms. HTML5 forms A component of a webpage that has form controls – Text fields – Buttons – Checkboxes – Range controls.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Tutorial 6 Creating a Web Form
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
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,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Chapter 5 Validating Form Data with JavaScript
CS 330 Class 7 Comments on Exam Programming plan for today:
Validation and Building Small Apps
Presentation transcript:

HTML Forms Validation CS360 Javascript

On to forms processing... The processing of a form is done in two parts: –Client-side at the browser, before the data is passed to the back-end processors –could be done via Javascript, VBScript or Jscript (might even be done via Java applets) –data validation done locally to relieve the back-end processors of having to do it –Server-side processing done in the back-end system –CGI Scripts –VBScript, JavaScript, Java –Database

HTTP Protocol Client Server Request Packet (GET or POST) Response Packet Request Packet Request Header (client info) Request Body (actual request) Response Packet Response Header (server info) Response Body (requested URL) Status Header Browser Web Server

Series of events The processing of a form follows the series of events: –user requests a form –form is received by browser, rendered and Javascript initialization processing is done. –User fills in form and any event processing required by form is performed –users click on a Submit Button –submission Javascript is run –if OK the data is submitted to the server via the method coded on the tag; i.e. by an http GET or POST. –Data sent to server is processed by the mechanism coded in the METHOD attribute of the tag.

GET and POST In the HTTP protocol, data from the client is sent to the server in one of two primary ways: –GET attaches the forms data (URL encoded) to the requested URL and places the URL in the body of an http request packet –usually the URL for a CGI-script to process the data or the URL for a meta processor (a ColdFusion, ASP or PHP page) as the URL has the data attached it is visible in the Location box of the browser, Since this allow the data (possibly a password) to be seen by any with in view of the screen it is not preferred. –POST places the forms data into the body of the http request packet, this way the data will not be seen by snooping eyes, it is far from secure but it is more private than GET. This is the preferred way to send data to the server.

Client-side Forms Processing... Now that we’ve been introduced to the components that can make up a form what can we do with them One major use of Javascript in conjunction with HTML forms is for validation of forms data before allowing the data to be submitted to a backend server for processing –doing the data validation at the client (browser) relieves the server from having to do it on a busy server this can free up a lot of processing cycles that can be better used to process more user requests and/or backend database functions. Most client machines are under-utilized and doing the validation at the client machine increases the utilization rate of the client machines usually client side processing MIPs are cheaper than server-side processing MIPs

Validation Functions Validation functions can usually be written in either of two ways –traditional iterative programming methodologies write a small program (function) that iterates through the user input and validates the data type and returns true or false depending on result requires Javascript level iterative processing –can be relatively slow, especially if form has many fields to be validated –pattern matching (via regular expressions, supported in Javascript 1.2 as in Perl 5) create a regular expression pattern for the data type and let the system validate the user input via the pattern matching capabilities of the pattern matching is done at a low level in the Javascript processor, so validation is very quick (even for long forms)

Approaches Point and click components (buttons, selection lists, radio buttons and checkboxes) don’t need to be validated unless there are rules that deal will combinations that need to be validated. This leaves text input fields –Validate each field as the user fills it in (using onBlur( )) if user fills in the field and then clicks Submit, the field won’t be checked –place all validation scripts in a single file for inclusion via SRC attribute of tag and place one forme specific script in each form that calles the validation routines for the individual fields means writing a script for each form –too costly and tedious –make a checkForm script that will iterate through a form’s elements array to validate entire form requires a naming convention for naming fields must be generic enough for handling all type of fields (dates, ssns, integers, reals, each form’s onSubmit invokes checkForm( )

Field Naming Convention First 3 chars of field name indicate type: –INT ; indicated field is to be an integer –DEC ; indicated a decimal number –DAT ; indicates a date field –SSN ; indicates a Social Security Number –LIT ; literal alphnumeric field If field is a certain length, follow type with length –INT5 ; integer between 0 and –LIT8; 8 character literal For required fields precede name with RQD or a special character – RQDINT3 ; required integer between 0 and 999 You get the idea; this technique is easily extensible –all it takes is a unique identifier –a new decoder in checkForm( ) –and new validation function in your included function library

Validation Functions Validation functions can usually be written in either of two ways –traditional iterative programming methodologies write a small program (function) that iterates through the user input and validates the data type and returns true or false depending on result requires Javascript level iterative processing –can be relatively slow, especially if form has many fields to be validated –pattern matching (via regular expressions, supported in Javascript 1.2 as in Perl 5) create a regular expression pattern for the data type and let the system validate the user input via the pattern matching capabilities of the pattern matching is done at a low level in the Javascript processor, so validation is very quick (even for long forms)

Regular Expression Syntax /n,/r,/t match literal newline, carraige return, tab \\, \/, \*match a special character literally, ignoring or escaping its special meaning […]Match any one character between the brackets [^…]Match any one character not between the brackets.Match any character other than the newline \w, \WMatch any word\non-word character \s, \SMatch any whitespace/non-whitespace \d, \DMatch any digit/non-digit ^, $require match at beginning/end of a string or in multi-line mode, beginning/end of a line \b, \Brequire a match at a word/non-word boundary ?Optional term : Match zero or one time +Match previous term one or more times

Regular Expressions (more) *Match term zero or more times {n}Match pervious term n times {n,}Match previous term n or more times {n,m}Match prev term at least n time but no more than m times a | bMatch either a or b (sub)Group sup-expression sub into a single term and remember the text that it matched \nMatch exactly the same chars that were matched by sup-expression number n $nIn replacement strings, substitute the text that matched the nth sub-expression

search( ) and test( ) A couple of very useful methods –search( ) - similar to indexOf( ) method on String String.search(regex) return -1 for no match; integer starting position if a match is found argument is a regular expression –test( ) method on regexObject returns boolean regex.test(String) false if no matches are found in String, true otherwise argument is a String

INT5 ; two ways inInt.search( ^ \ + | \ - ? \ d{1,2,3,4,5} $ / ) –at the beginning of a line there may be a plus or, 0 or 1 minus’, followed by one or two or three or four or five digits at the end of the line the plus is escaped (preceded with a \ ) as it is also meta character r1 = ^ \ + | \ - ? \ d{1,2,3,4,5} $ / ; if (r1.test( field. value))...

HTML5 Validation New attributes for –required =‘required’ –pattern= ‘a regular expression’ can be used with types, text, search, url, telephone, , and password. –min= max = step= can be used with