...

View Full Version : Help with form



steiger16
05-23-2011, 01:24 AM
Hi, I need help with my contact form. It is not working for some reason. Kinda new to PHP so help would be appreciated.

HTML SNIPPET


<form action="contact.php" method="post" id="contactform">
<ol>
<li>
<label for="name">Full Name</label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email"> Email Address</label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="phone">Phone Number</label>
<input id="phone" name="company" class="text" />
</li>
<li>
<label for="company">Wedding Date</label>
<input id="company" name="company" class="text" />
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="street">Street Address</label>
<input id="street" name="subject" class="text" />
</li>
<li>
<label for="city">City</label>
<input id="city" name="subject" class="text" />
</li>
<li>
<label for="state">State</label>
<input id="state" name="subject" class="text" />
</li>
<li>
<label for="zip">Zip Code</label>
<input id="zip" name="subject" class="text" />
</li>
<li>
<label for="message">Message</label>
<textarea id="message" name="message" rows="4" cols="5"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" />
</li>
</ol>
</form>
PHP MAILER SNIPPET


<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array ('name','email','message');

$your_email = "nicksteig@steigdesign.com";
$email_subject = "Email from Contact Page: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}

if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>

tangoforce
05-23-2011, 01:25 AM
Please check out the [php] link in my signature.

steiger16
05-23-2011, 01:26 AM
sorry

tangoforce
05-23-2011, 01:27 AM
No need to apologise, just read it and edit your post ;)

steiger16
05-23-2011, 01:44 AM
better? ;)

steiger16
05-23-2011, 01:45 AM
This code was taken from a template that I purchased and am trying to get it to work for my current needs.

tangoforce
05-23-2011, 02:22 AM
Yes much better ;)

So what is the actual problem? - Does it not do anything? Is there an error message? - So far all you've done is say you got this as a template, shown the code and told us its not working for some 'reason'.

If you can give us some better details we'll be able to help you further.

djh101
05-23-2011, 02:23 AM
What are you trying to do and what about it isn't working?

steiger16
05-23-2011, 02:44 AM
when you fill out the form and click submit, it returns error. I even have it uploaded as a php page on my server. Not sure what is going on. This was a template but then I edited it just to add more fields in.

djh101
05-23-2011, 03:03 AM
Post the error, if you could.

My assumption: All of your forms have the same name; the name should be unique (since the name is what is used to call the form data, e.g. $_POST['field1'] will contain the data for an input field named 'field1'.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum