LESSON 6: PHP IN ACTION

LESSON 6




PHP In Action




Using PHP


PHP code needs to be added between <?php and ?> comments. PHP looks similar to jQuery, but it does have different purposes and functions. For our example we will create a “Contact Us” form. This form will contain name, email address, phone number, and other user notices. For our Contact Us form the PHP will look something like this:

<?php
$headers="From: Confirmation@MindWorksInMotion@gmail.com \r\n";
//$headers="From: ".fromemail."\r\n";
$headers.="MIME-Version: 1.0" . "\r\n";v $headers.="Content-type:text/html;charset=iso-8859-1"."\r\n";
$headers.="Customer Feedback";
$to="MindWorksInMotion@gmail.com";
$subject="Customer Feedback";
$message="<br />Name :".$_POST['Full_name']."<br/>";
$message.="Email :".$_POST['Email_address']."<br/>";
$message.="Phone :".$_POST['Phone_number']."<br/>";
//$message.="Subject :".$_POST['subject']."<br/>";
$message.="Message :".$_POST['Comment_box']."<br/>";
mail($to,$subject,$message,$headers);
echo("Dear ".$_POST['Full_name']."<br>");
echo("Thank you for your email submission.");
?>

In the above PHP we are designating certain areas for the structure of an email. Some of these areas include the header information, message information, the subject, who it is going to and coming from, and a confirmation message that is generated by the “echo” statement. Most of these areas are self-explanatory.

In addition to this PHP we will need a section which will be the actual form on our webpage. The PHP is not visible to the user and is only accessed after the form has been completed, submitted and validated (if you are using validation). An example of the HTML for section of code that will generate a Contact Us input area will look something like this:

<form action="php/contact_process.php" method="post" id="form_contact" onSubmit="MM_validateForm('Full_name','','R','Email_address',
'','RisEmail','Phone_number','','RisNum','Comment_box','','R');return document.MM_returnValue">

<label id="Full_name_l">Your Full Name:</label> <input type="text" name="Full_name" id="Full_name" /> <br /><br />

<label id="Email_address_l">Email Address: </label><input type="text" name="Email_address" id="Email_address" /><br /><br />

<label id="Phone_number_l">Phone number:</label><input type="text" name="Phone_number" id="Phone_number" /><br /><br />

<label id="Comment_box_l">Comment: </label><textarea name="Comment_box" cols="35" rows="10" id="Comment_box">

</textarea></br><br>

<input type="submit" name="Submit" id="submit_1" value="Submit" />

</form>

The above code may seem complicated, but it is essentially using input tags to collect information that will pass on to the server via the PHP. Please note that in the first line the actual PHP file needs to be accessed and is called by using the command
<form action="php/contact_process.php". The above code when used on an HTML webpage will look like this:

Please Contact Us!









This concludes this Intermediate Web Design tutorial. If you would like to contact us, we would love to hear from you. You can either use the input form above, which is active and operational, or you can go directly to the Contact Us page and send us a message from there. I hope you have enjoyed this tutorial, that you have learned something new, and that you know more now than you knew when you started it.

Peace, knowledge, and understanding to you!

PREVIOUS: PHP
THE END : Contact Us