BRINGING FORMS TO LIFE Figure 5-6. Quotes within (Web design careers)
Monday, December 17th, 2007BRINGING FORMS TO LIFE Figure 5-6. Quotes within user input need special treatment before form fields can be redisplayed. Passing the content of the $_POST array element to the htmlentities(), however, converts the double quotes in the middle of the string to ". And, as Figure 5-7 shows, the content is no longer truncated. What s cool about this is that the HTML entity " is converted back to double quotes when the form is resubmitted. As a result, there s no need for any further conversion before the email can be sent. Figure 5-7. The problem is solved by passing the value to htmlentities() before it s displayed. By default, htmlentities() leaves single quotes untouched. Since I chose to wrap the value attribute in double quotes, this doesn t matter. To convert single quotes to an HTML entity as well, pass ENT_QUOTES (all uppercase) as a second argument to htmlentities() like this: htmlentities($_POST[’name’], ENT_QUOTES) 2. Amend the email input field in the same way, using $_POST[’email’] instead of $_POST[’name’]. 135
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.