Flash / AS

Blend / WPF
ASP.net / PHP

Photoshop

Forums
Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

 

 

 
PHP
Contact Form - More Form Elements
         by kirupa : 20 December 2004

In the previous page, I described how checkbox data can be processed and sent via e-mail. On this page I'll quickly run-through option buttons and drop-down menus.

Option (Radio) Buttons and Drop-Down Menus
The following is both the HTML and PHP code for our contact form with the code for the option buttons and drop-down menus emphasized:

<form method="POST" action="mailer.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>
 
<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
<br>
<input type="radio" value="yes" name="radio"> YES<br>
<input type="radio" value="no" name="radio"> NO
<br>
<br>
 
<select size="1" name="drop_down">
<option>php</option>
<option>xml</option>
<option>asp</option>
<option>jsp</option>
</select><br>
<br>
Message:<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="submit">
</form>

Not to be left behind, here is the PHP code tagging along:

<?php
if(isset($_POST['submit'])) {
 
$to = "you@you.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];
 
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
 
$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
 
} else {
echo "blarg!";
}
?>

Explanation
As you can tell from the above code, the option buttons and drop-down menu behave similarly to our text field and message area form elements. The reason is that nothing fancy is going on behind the scenes.

Note the code that is colored in red in the HTML code, and find its corresponding red code in the PHP code. I highlighted the code in pink in the PHP code to simply show that I still combine these new pieces of data into our ever-expanding $body variable.


Well, that is it to this tutorial that explains how to use PHP to send form data to your e-mail account. I have provided the PHP and HTML file for you to download.

Download ZIP

I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the kirupa.com Forums. Just post your question and I, or our friendly forum helpers, will help answer it.

The following is a list of related tutorial and help resources that you may find useful:

How to use the Forums
New, Upcoming, and In-Progress Tutorials
How to Help out kirupa.com
Writing Tutorials
 
Cheers!
Kirupa Chinnathambi
kirupaBlog

 


page 4 of 4


 


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components

Flash Templates
CSS Templates
Dreamweaver Templates

flash menus, buttons and components
Digicrafts Components The best flash components ever!
Entheos Flash Website Templates Free Flash Page Flip
flash components Buy and sell FLAs at Ultrashock!
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com create flash slideshow as easy as 1,2,3
Learn how to advertise on kirupa.com