Computer Science Canada

Creating fill-out forms

Author:  wthef_wc3 [ Tue Jul 05, 2005 7:17 pm ]
Post subject:  Creating fill-out forms

Im not sure if this is the right spot but...
Im trying to make a fill out form (ie. text boxes checkboxes ect.) that sends the values of each component to my email address
i am using dreamweaver mx and i can create one that sends to my email but only the data from textboxes, and it requires the user to enter a valid email address.
any idea?
ps if possible can u point me to a good form making tutorial.

Author:  JackTruong [ Sat Jul 09, 2005 9:46 pm ]
Post subject: 

First thing you have to know is the $_POST and/or the $_GET variables. They get created when a form is submited. $_POST stores the information within the page, while the $_GET has the information in the URL.

How does this relate to the forms?

php:
<?php
if (isset($_POST['name']))
{
echo $_POST['name'];
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="name" />
<input type="submit" value="Click" name="click" />
</form>

Try that out, keep in mind the name= part of the input tags, they relate to the $_POST/$_GET variable.

As you can now see, the name of the input field corresponds to the $_POST variable.

name="<name>"
$_POST['<name>'];
$_GET['<name>'];

That should take care of the majority of this tutorial. Add as many input fields as you wish, keeping in mind that each name must be different. Radio buttons, <SELECT>, and checkboxes are a bit trickier, but they shouldn't be too much of a problem.

Now you have all the information in the $_POST or $_GET variables, you want to send the information. I strongly suggest taking a look at PHP.net's mail() function page and putting all the variables together in one big string for the third parameter.

Valid e-mail address can be done via PHP
php:

if ($_POST['email'] == "someemail@domain.ext")
{
// the email is fine, do something with it.
}


Hope I was clear on this one.

Author:  Blade [ Sat Aug 13, 2005 11:17 am ]
Post subject: 

mail(); will allow you to use sendmail on the server to send emails through php, which obviously means that the server will have to have sendmail on it to use it.

go to http://ca.php.net/manual/en/function.mail.php for more infromation and examples on the function

i'll assume that you know how to make forms, i'll just show you how it works

HTML:

<form method="post" action="form.php">

<!-- action="form.php" is the file that the info is sent to -->

<input type="text" name="title"><br>
<textarea name="message"><br><br>
<input type="submit">
</form>


this will be the simplest way to send an email with mail(); if you want to send extra headers and such see that link
php:
//form.php
<?
  $email = "someguy@something.com"; //your email address, or the email you want it sent to
  if(!mail($email, $_POST['title'], $_POST['message'])){
    die("Error sending email");
  }

?>


: