PDA

View Full Version : need help with the DW and PHP tutorial


paispais
06-04-2007, 05:22 PM
After reading the instructions about a hundred times, I'm sure, I'm missing something in the code. I'll describe the problem, when I load the page containing the contact form and php code, the page instantly goes to the confirm page(the page that loads after the user clicks on the "send" button). I got it to work once and now I can't remember what I did. Can anyone understand what I'm explaining here or would it be easier to paste the code in this thread?

Mark_W
06-04-2007, 06:10 PM
Paste the code in the thread, you will be able to get maximum help that way.

paispais
06-04-2007, 06:46 PM
<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Somerset Contact Form';

// Your email address. This is where the form information will be sent.
$emailadd = 'shawn@mydomain.net';

// Where to redirect after form is processed.
$url = 'confirm.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>


<!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=ISO-8859-1" />
<title>Somerset</title>
<link href="lomax.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>
<div class="Dtop">
<img src="images/top.jpg" width="930" height="300" />
</div>
<div id="contentContainer">

<div id="MenuContainer">
<a href="home.html">Home</a>
<a href="floorplans.html">Floorplans</a>
<a href="condo_amenities.html">Condominium Amenities</a>
<a href="sales.html">Sales</a>
<a href="news.html">In the News</a>
<a href="contact.html" id="selected">Contact Us</a>
</div>
<div id="midD">
<p>&nbsp;</p>
<h1>Contact</h1>
<form action="contact.php" method="post" name="Contact Form" id="Contact Form">
<div class = "contactContainer">
<div class="contactTitles">e-mail</div>
<div class="contactBoxes"><input name="email" type="text" id="email"></div>
</div>
<div class = "contactContainer">
<div class="contactTitles">name</div>
<div class="contactBoxes"><input name="name" type="text" id="name"></div>
</div>
<div class = "contactContainer">
<div class="contactTitles">comments</div>
<div class="contactBoxes"><textarea name="comments" cols="30" rows="5" wrap="VIRTUAL" id="comments"></textarea></div>
</div>
<div class="contactContainer">
<input name="send" type="submit" id="send" value="Send" />
</div>
</form>


<br />


</div>
<div class="footer">

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

davidj
06-04-2007, 07:22 PM
this is the line causing the problems...

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

If you want this to fire on the click of a button you need to wrap that line in a conditional IF statement.

paispais
06-04-2007, 08:00 PM
this is the line causing the problems...

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

If you want this to fire on the click of a button you need to wrap that line in a conditional IF statement.

Ok, something like this here.

<?php
if (sendBtnOnPress == true)
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>I'm totally lost on how to set-up the expression. How would the code know if the send button in pressed?:confused:

davidj
06-04-2007, 08:15 PM
ok

here is a button...

<input type="button" name="email" id="email" value="email" />


do this...
notice the doit variable and value and the page name (mailpage.php) which you would change to suit

<input type="button" name="email" id="email" value="email" onclick="mailpage.php?doit=1"/>

/////////////////////////////

ok in the mail script you could wrap the whole thing in an IF
notice how i catch the doit var. I dont have to check the value just check it contains something then i know its been submitted

if(isset($_GET['doit'])){

//run the mail script here

}

paispais
06-05-2007, 02:07 PM
I understand it now and it works good. Thank you.