If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example, an confirmation (Don’t become a spammer.) (Be careful about ing sensitive inofrmation.)
Design of a form
Display code (no yet)
Result so far (no yet)
Searching for an regular expression (at
Pick one with a good rating
Client-side validation
Client-side validation (Cont.) var = document.getElementById("txt ").value; = .replace(/^\s+|\s+$/g, ''); Get the string entered by the user from text field Use the string function replace and the regular expression for white space to make a JavaScript version of the trim function. (// format.php)
Client-side validation (Cont.) var Pattern = new 9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/); Declare and initialize a JavaScript regular expression. –Source: –Author: David Lott
Client-side validation (Cont.) if(! .match( Pattern)) { alert("Please enter a proper ."); return false; } Do not send information to server if the user’s does NOT (!) match the pattern regular expression.
Server-side: code
Server-side: code (Cont.) 9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/",$ )) { print " You entered an invalid and we cannot confirm for registration. "; } Validate using regular expression. Remember never rely on your client-side validation – you need to validate on the server side as well.
Server-side: code (Cont.) else { //used below in $extra $extra = "from: $return_address\nContent-type: text/html; charset=iso "; $subject = "ACT Training Registration Confirmation"; If the is valid, prepare some variable that will be used by the mail function Note that the return address becomes part of a longer variable that indicates that the ’s body will use HTML formatting.
Server-side: code (Cont.) $body = " "; $body = $body. " $firstName $lastName, thank you for registering for "; $body = $body. " the following workshop. "; $body = $body. " $workshops[$session] "; $body = $body. " You have selected a $lunch[$lunchChoice] for lunch. "; $body = $body. " "; The body starts and ends with HTML tags and encloses the ’s text. Recall that the period. corresponds to concatenation, so $body = $body. “something” adds something to whatever value the variable $body already has.
Server-side: code (Cont.) mail($ ,$subject,$body,$extra); The mail function above has four arguments: –The first is the address to which the will be sent. –The second is the subject field of the –The third is the actually content of the message (here it was put in HTML format) –The fourth includes a return address as well as an indication that we are using HTML formatting
Result (this part is the same as before)
Resulting