mail form

source: http://www.thegoldenmean.com

Page Six: Additional Fields

In response to numerous questions from readers, this page covers how to add additional input fields and send them along with the basic message as covered in previous pages. Some readers have wanted to capture phone numbers or mailing address or other data specific to their site’s needs. If you also need radio buttons, check boxes, drop down menus or other UI widgets, that goes beyond what I can cover in this intro tutorial. I will limit this page’s discussion to sending text data captured in additional text input fields.

On the Flash side…

On the Flash side of things it’s easy because you can use the examples in the previous pages of this tutorial and thedemo files as a model. You will need to:

On the PHP side…

It’s a little trickier on the PHP side of things, but it’s mainly just a matter of being methodical. Here’s the issue: the PHP mail() function can only send one variable. For this tutorial let’s say we have decided to call that variable "$fullMessage". (You can name your combined variable whatever you wish of course, but if you choose to name it something else be sure to change the code examples that follow.)

You will need to string together (concatenate) ALL the various bits of data from your form into this one variable because that’s all PHP can send.

PHP uses the dot or period symbol to join text literal strings and variable values together. Let’s say for example that your Flash form sends name, age, city and comments as variables to the processEmail.php script. In that PHP script it would be sensible to store them as variables with self-explanatory variable names such as $name, $age, $city and $comments. To merge them into the $fullMessage variable you would do something like:

$fullMessage = $name.$age.$city.$comments;

That will certainly work, but when you receive the message it’s going to look ugly and be difficult to read because it will be all run together without any breaks or new lines. You will most likely wish to apply some simple formatting, primarily displaying the submitted input items on separate lines. In PHP the newline character is \n, which should be enclosed in double quotes so the PHP interpreter knows to parse it as a newline character. To make things look nicer you might wish do something like the following:

$fullMessage = "Name: ".$name."\nAge: ".$age."\nCity: ".$city."\nComments: ".$comments;

Then in the PHP mail() function you send $fullMessage (or whatever you choose to call it) as the third argument. Something like:

mail($toaddress,$subject,$fullMessage,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\n");

That’s it! Good luck with your Flash contact form.

divider ornament

--top--