Copy link to clipboard
Copied
Hello Peeps
Just started playing around in web design, i managed to acquire a template for my golf society friends, but i am unable to get the correct php form set up for the contact page. The code for the Form is below.
<form id="ContactForm" action="email.php" method="post">
<div>
<label><span class="input"><input type="text" value="Your Name:" onBlur="if(this.value=='') this.value='Your Name:'" onFocus="if(this.value =='Your Name:' ) this.value=''" /></span></label>
<label><span class="input"><input type="text" value="Your E-mail:" onBlur="if(this.value=='') this.value='Your E-mail:'" onFocus="if(this.value =='Your E-mail:' ) this.value=''" /></span></label>
<label><span class="input"><input type="text" value="Your State:" onBlur="if(this.value=='') this.value='Your State:'" onFocus="if(this.value =='Your State:' ) this.value=''" /></span></label>
<span class="textarea"><textarea onBlur="if(this.value=='') this.value='Your Message:'" onFocus="if(this.value =='Your Message:' ) this.value=''" >Your Message:</textarea></span>
</div>
<div class="alignright">
<a href="#" class="link" onClick="document.getElementById('ContactForm').reset()"><span><span>clear</span></span></a>
<a href="#" class="link" onClick="document.getElementById('ContactForm').submit()"><span><span>send</span></span></a>
</div>
</form>
I have searched the net for a solution and found the below, but i cannot get the message content to appear in the emails.
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Results from Contact form';
// Your email address. This is where the form information will be sent.
$emailadd = 'feedback@wsog.co.uk';
// Where to redirect after form is processed.
$url = 'http://www.wsog.co.uk/Contact.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 = '1';
// --------------------------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.'">';
?>
any tips on how i can get the text to send would be very greatfull.
Your input and textarea fields do not have names. The name becomes the key used by the post superglobal. Without it, nothing will be passed to the POST upon submit. So, for instance, where you have value="Your State:" you shoud follow that with name="state"
Copy link to clipboard
Copied
Where are you testing this that it is not working?
Copy link to clipboard
Copied
Your input and textarea fields do not have names. The name becomes the key used by the post superglobal. Without it, nothing will be passed to the POST upon submit. So, for instance, where you have value="Your State:" you shoud follow that with name="state"
Copy link to clipboard
Copied
What Rob means is you didn't name the fields in your form. Here is the code if that doesn't make sense:
Contact Form:
====================
<form id="ContactForm" action="email.php" method="post">
<div>
<label><span class="input"><input name="name" type="text" id="name" onFocus="if(this.value =='Your Name:' ) this.value=''" onBlur="if(this.value=='') this.value='Your Name:'" value="Your Name:" /></span></label>
<label><span class="input"><input name="email" type="text" id="email" onFocus="if(this.value =='Your E-mail:' ) this.value=''" onBlur="if(this.value=='') this.value='Your E-mail:'" value="Your E-mail:" /></span></label>
<label><span class="input"><input name="state" type="text" id="state" onFocus="if(this.value =='Your State:' ) this.value=''" onBlur="if(this.value=='') this.value='Your State:'" value="Your State:" /></span></label>
<span class="textarea"><textarea name="comments" id="comments" onFocus="if(this.value =='Your Message:' ) this.value=''" onBlur="if(this.value=='') this.value='Your Message:'" >Your Message:</textarea></span>
</div>
<div class="alignright">
<a href="#" class="link" onClick="document.getElementById('ContactForm').reset()"><span><span> clear</span></span></a>
<a href="#" class="link" onClick="document.getElementById('ContactForm').submit()"><span><span >send</span></span></a>
</div>
</form>
Changing your code to this in your form will make it work. I've tested it.
Give Rob the correct answer however. As I've only provided the code and offered no insight.