BRINGING FORMS (Web hosting comparison) TO LIFE if (function_exists(’nukeMagicQuotes’)) { nukeMagicQuotes();
Sunday, December 9th, 2007BRINGING FORMS TO LIFE if (function_exists(’nukeMagicQuotes’)) { nukeMagicQuotes(); } ?> The file corefuncs.php contains the function nukeMagicQuotes(). To prevent errors if corefuncs.php can t be accessed, the call to nukeMagicQuotes() is wrapped in a conditional statement using function_exists() as described in the last chapter. 5. Save contact.php and click the Reload button in your browser. Confirm that you want to resend the post data. The $_POST array should now be clear of backslashes, as shown in Figure 5-4. You can check your code with contact03.php. Figure 5-4. The nukeMagicQuotes() function cleans up the $_POST array ready for use in an email. Processing and acknowledging the message You can now build the message body with the contents of the $_POST array and email it to your inbox. You also need some way of informing the user that the message has been sent or if there is a problem. Rather than redirect the user to a different page, the following PHP Solution displays the result on the same page. I ve adopted this approach because an improved version later in the chapter redisplays the user s input if any required fields are missing. Once the final version of the form is complete, you can redirect the user to a separate acknowledgment page by adding only two lines of code. PHP Solution 5-2: Sending email from the feedback form Continue using the same files. Alternatively, use contact03.php from the download files. 1. Now that you have finished testing the $_POST array, delete the following three lines of code that were used to display its contents (they re just after the closing
tag):
125
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.