PDA

View Full Version : Activating my form in Dreamweaver


K.Simmonds
06-16-2009, 06:32 AM
I was getting good replies from edbr, but my questions have gone onto page 2 and I don't think they're being read (I posted the same question twice because I didn't see it myself). Anyway, in case edbr (in Bali) is reading this, here's a copy of what I posted last.

--------------------------------------

I've been struggling with this all weekend, and I think I've got a bit further. I created a Php file, called submit.php, and uploaded it. When you fill in the form on the website ( http://www.twohoots.info/Pages/contact.html ) you get the message Thankyou Mr, your name is, your address is, your postcode is etc, but it still won't send me an email. The code I've written is below. What have I done wrong?


<html>
<body>
Thank You <?php echo $_POST["Mr"]; ?> <?php echo $_POST["Name2"]; ?>. <br />
Your E-Mail is <?php echo $_POST["email"]; ?> <br />
Your Address is <?php echo $_POST["Address"]; ?> <br />
Your Post code is <?php echo $_POST["Post code"]; ?> <br />
Your Start Date is <?php echo $_POST["Start Date"]; ?> <br />
Your Leaving Date is <?php echo $_POST["Leaving Day"]; ?> <br />
Number of Adults is <?php echo $_POST["Adults"]; ?> <br />
Number of Children is <?php echo $_POST["Children"]; ?> <br />
Your comments were <br />
<?php echo $_POST["Additional info"]; ?> <br />
<?php

$SendEmail ="keith@glendalehouse.co.uk";
$message = $_POST["Mr"] . " <br /> " . $_POST["Name2"] . " <br />" . $_POST["email"] . " <br />" . $_POST['addr'] . $_POST["Post code"] . " <br />" . $_POST["Start Date"] . " <br />" . $_POST['Leaving Day'] . " <br />" . $_POST['Adults'] . "<br />" . $_POST['Children'] . " <br />" . $_POST['Aditional info'];
$body = <<< EOD
EOD;

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$sucess = mail($SendEmail, $emailSubject, $message, $headers, '-f'.$SendEmail);
?>

</body>
</html>
__________________
Keith Simmonds

edbr
06-16-2009, 07:18 AM
ok i just wrote this and tested it and it definitely works
add your email address only save it as mailtest, then call it in your browser. you will see invalid email address. fill in a correct emailand send it. If you dont get itthen the problem is with your hosting
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<label>E mail
<input type="text" name="email" id="email" />
</label>
<input name="send" type="submit" value="Submit" />
</form>

<?php

$email = $_POST['email'];

$from = "From:$email \r\n";
$recipient= "keith@glendalehouse.co.uk";


$message = "This is a test email . php is working";


/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($email == "") {
echo "<h4>You must enter an e mail address</h4>";
echo "<a href='javascript:history.back(1);'>Back to e mail form</a>";
}

elseif (mail($recipient,$email,$message, $from)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email</h4>";
}

?>

</body>
</html>

K.Simmonds
06-16-2009, 10:01 AM
Where do I copy that code? It hasn't got any of the info in it (Mr,Mrs,Address,Postcode,Arrival date etc.).

edbr
06-17-2009, 01:24 AM
ok i just wrote this and tested it and it definitely works
1.save it as mailtest.php, then call it in your browser.
2. you will see invalid email address
3.fill in a correct email and send it.

If you dont get it then the problem is with your hosting

this is a test to see if your hosting is working re sending , if it works then it is easy to alter and ill walk you through it , if not the problem is elsewhere.
so upload it and then go to your_domain.com/mailtest.php

K.Simmonds
06-18-2009, 07:24 AM
Fabulous. Major step forward. I got an email saying "This is a test email . php is working". Now I need it to send all the information as well (Name, address, start date, leaving date etc). Thanks a lot for your help so far. How's the weather?

K.Simmonds
06-18-2009, 07:31 AM
Incidentally - I copied your code into my submit.php file right after the existing code (was that right?). Don't forget this forum page might spill over to page 2 again.

edbr
06-18-2009, 08:10 AM
no make a separate file as i said. i was trying to test your process step by step.
If it works you will just need to add Post variables and code your $message

K.Simmonds
06-18-2009, 08:34 AM
OK I've taken all the original code out of my submit.php file, and just left yours there. It works - I get the email saying it works.

edbr
06-18-2009, 08:46 AM
ok, ill re write it for you , what are your form fields called?

edbr
06-18-2009, 09:07 AM
Ok try this i looked at your page , I have renamed your fields to remove spaces please note new names and change your field to take them out, they must match the $_POST names i have added
save this as your action page as named in your form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<label>E mail
<input type="text" name="email" id="email" />
</label>
<input name="send" type="submit" value="Submit" />
</form>

<?php

$email = $_POST['email'];

$from = "From:$email \r\n";
$recipient= "keith@glendalehouse.co.uk";
<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = $_POST['email'];
$name = $_POST['name2'];
$subject = $_POST['subject'];
$telephone = $_POST['Telephone'];
$address = $_POST['Address'];
$status = $_POST['Mr'];
$postcode = $_POST['Postcode'];
$startdate = $_POST['Startdate'];
$leavingday = $_POST['Leavingday'];
$children = $_POST['Number_of_children'];
$adults = $_POST['Adults'];


Additional info

$message = "$from \n
name $name \n
e mail address $email \n
Address $address \n
Post code $postcode \n
tTelephone $telephone \n
Start date $startdate \n
Leaving day $leavingday \n
Number of children $children

";


/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($email == "") {
echo "<h4>You must enter an e mail address</h4>";
echo "<a href='javascript:history.back(1);'>Back to e mail form</a>";
}

elseif (mail($recipient,$email,$message, $from)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email</h4>";
}

?>

</body>
</html>
</body>
</html>

K.Simmonds
06-18-2009, 09:18 AM
I really do appreciate this. They are:

Title (Mr / Mrs / Miss dropdown box)
Name
Address
Postcode
Telephone
Email
Arrival day
Leaving day
Number of adults (1 - 6 dropdown box)
Number of children (0 - 4 dropdown box)
Any additional information

The form is still on http://www.twohoots.info/Pages/contact.html

and the form code inside the "contact" page is:

<form id="Two Hoots Enquiry Form" name="Two Hoots Enquiry Form" method="post" action="submit.php">
<table width="593" border="0">
<tr>
<th width="219" scope="col"><div align="left" class="style40">Title</div></th>
<th width="364" scope="col">
<div align="left">
<select name="Mr" id="Mr">
<option selected="selected">Mr</option>
<option>Mrs</option>
<option>Miss</option>
</select>
<input name="hiddenField" type="hidden" id="hiddenField" value="&lt;input type=&quot;hidden&quot; name= &quot;sendto&quot; value=&quot;keith@glendalehouse.co.uk&quot;&gt;" />
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Name</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Name2" id="Name2" />
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Address</div></th>
<th scope="col"><div align="left">
<label>
<textarea name="Address" id="Address" cols="45" rows="5"></textarea>
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Post Code</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Post code" id="Post code" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Telephone</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Telephone" id="Telephone" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Email</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="email" id="email" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Dates Req'd (Arrival day)</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Start date" id="Start date" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Dates req'd (Leaving day)</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Leaving day" id="Leaving day" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Number of adults</div></th>
<th scope="col"><div align="left">
<label>
<select name="Adults" id="Adults">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Number of children</div></th>
<th scope="col"><div align="left">
<label>
<select name="Children" id="Children">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Any additional information?</div></th>
<th scope="col"><div align="left">
<label>
<textarea name="Additional info" id="Additional info" cols="45" rows="5"></textarea>
</label>
<br />
</div></th>
</tr>
<tr>
<th height="72" valign="top" scope="col">&nbsp;</th>
<th scope="col"><label>
<input type="submit" name="button" id="button" value="Submit" />
</label></th>
</tr>
</table>

</form>

K.Simmonds
06-18-2009, 09:59 AM
Oh dear. I think I've screwed up. I did it (I think) and uploaded both the "contact" and th "submit.php" files, but now when I fill in the form on the website, I get the message:

Parse error: parse error in /vhost/vhost6/t/w/o/twohoots.info/www/Pages/submit.php on line 29

The code in my "submit.php" page is copied and pasted from yours, and the code for the form on my "contact" page now looks like this.

<form id="Two Hoots Enquiry Form" name="Two Hoots Enquiry Form" method="post" action="submit.php">
<table width="593" border="0">
<tr>
<th width="219" scope="col"><div align="left" class="style40">Title</div></th>
<th width="364" scope="col">
<div align="left">
<select name="Mr" id="Mr">
<option selected="selected">Mr</option>
<option>Mrs</option>
<option>Miss</option>
</select>
<input name="hiddenField" type="hidden" id="hiddenField" value="&lt;input type=&quot;hidden&quot; name= &quot;sendto&quot; value=&quot;keith@glendalehouse.co.uk&quot;&gt;" />
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Name</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Name2" id="Name2" />
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Address</div></th>
<th scope="col"><div align="left">
<label>
<textarea name="Address" id="Address" cols="45" rows="5"></textarea>
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Post Code</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Post code" id="Post code" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Telephone</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Telephone" id="Telephone" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Email</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="email" id="email" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Dates Req'd (Startdate)</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Start date" id="Start date" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Dates req'd (Leavingday)</div></th>
<th scope="col"><div align="left">
<label>
<input type="text" name="Leaving day" id="Leaving day" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Adults</div></th>
<th scope="col"><div align="left">
<label>
<select name="Adults" id="Adults">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</label>
</div></th>
</tr>
<tr>
<th scope="col"><div align="left" class="style40">Number_of_children</div></th>
<th scope="col"><div align="left">
<label>
<select name="Children" id="Children">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</label>
</div></th>
</tr>
<tr>
<th valign="top" scope="col"><div align="left" class="style40">Any additional information?</div></th>
<th scope="col"><div align="left">
<label>
<textarea name="Additional info" id="Additional info" cols="45" rows="5"></textarea>
</label>
<br />
</div></th>
</tr>
<tr>
<th height="72" valign="top" scope="col">&nbsp;</th>
<th scope="col"><label>
<input type="submit" name="button" id="button" value="Submit" />
</label></th>
</tr>
</table>

</form>

K.Simmonds
06-18-2009, 01:50 PM
Its gone on to page 2 again !

edbr
06-19-2009, 12:41 AM
ok im running out of time i have a plane to catch. but you can add your original
$message = $_POST["Mr"] . " <br /> " . $_POST["Name2"] . " <br />" . $_POST["email"] . " <br />" . $_POST['addr'] . $_POST["Post code"] . " <br />" . $_POST["Start Date"] . " <br />" . $_POST['Leaving Day'] . " <br />" . $_POST['Adults'] . "<br />" . $_POST['Children'] . " <br />" . $_POST['Aditional info'];
in place of the $message that i put in my page i coded for you

but watch for any typos is aditional corect ?)
and change form fields to nbe either one word or linked with -
you will have to make sure that if your form field is called for example :

LeavingDay then its collected value must be the same
$_POST["LeavingDay"]

K.Simmonds
06-22-2009, 02:59 PM
Help. 22nd June ...... and I'm still stuck.

K.Simmonds
06-27-2009, 08:23 AM
Hi EDBR ........ are you hooked up to a PC yet. Its now the 27th June, and I'm still no further forward.

edbr
07-13-2009, 03:54 AM
ok post what you have now

K.Simmonds
07-19-2009, 09:17 AM
Hey, thank goodness you've re-surfaced. Somewhere nice again ???

Just to refresh your memory, the last form (not working) is still on the web page http://www.twohoots.info/Pages/contact.html so you can view the code on the page source.