Forum Moderators: coopster

Message Too Old, No Replies

Another Form Question

newbie looking for contact form help

         

gLocklin

2:05 am on Sep 10, 2009 (gmt 0)

10+ Year Member



Hello all!

i've recently opened a business. i learned html, css, illustrator and photoshop over the past month to be able to build my site - not knowing i'd need any php knowledge at the end of this. i'm kind of going crazy and my site is already built.

i styled a contact form but have a few questions.

here's the html:

 <form id="contact-form" method="post" action="/scripts/mailer3.php">


<fieldset>
<h2>Your info</h2>
<div class="field">
<div class="col col-left">
<label for="name">Your name</label><br>
<input name="name" id="name" class="input-text" type="text">
</div>
<div class="col col-right">
<label for="company">Company or organization</label><br>
<input name="company" id="company" class="input-text" type="text">
</div>
</div>
<div class="field last-field">
<div class="col col-left">
<label for="email">E-mail</label><br>
<input name="email" id="email" class="input-text" type="text">
</div>
<div class="col col-right">
<label for="phone">Phone or Skype</label><br>
<input name="phone" id="phone" class="input-text" type="text">
</div>
</div>
</fieldset>

<fieldset>

<h2>Additional Info / Message</h2>

<div class="field">
<label for="message">Please add a short message:</label><br>
<textarea name="message" id="message" cols="50" rows="5"></textarea>
</div>

<div class="field last-field">
<p class="smallnote">Individuals, please include any injuries or preexisting physical conditions.
<br><br>
Companies, please include number of employees and days requested.</p>
</div>


</fieldset>

<fieldset id="button-fieldset">
<label for="cc" class="label-check">
<input class="input-check" name="cc" id="cc" value="1" checked="checked" type="checkbox"> Receive a copy of this message?
</label>
<input class="input-hidden" name="submited" value="1" type="hidden">
<input class="input-image" src="img/send-message.gif" alt=" [ send message ] " type="image">
</fieldset>

</form>

and the php i'm using:

<?php
//If the form is POSTed, do the following
if($_SERVER['REQUEST_METHOD'] == 'POST') {

//Get the POSTed data and store in the $ variables
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

//If the name field is blank, retun the below error
if(!$name)
{
echo "You must enter a name.";
}

//If the email address field is blank, retun the below error
if(!$email)
{
echo "You must enter an email address";
}

//If the email address entered appears to be of an incorrect format return the below error
elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
echo "You must enter a valid email address";
}

//If the phone number field is blank, retun the below error
if(!$phone)
{
echo "You must enter a phone number";
}

if(!$errors)
{
$msg = "Full Name: $name\n\nCompany: $company\n\nEmail Address: $email\n\nPhone: $phone\n\nMessage: $message\n\n";

mail("me@mydomain.com", "Website Enquiry", $msg, "From: $name <$email>");

header('Location: mysite.com/thankyou.html');
}
}
?>

i want to to one of two things:

i'd either like an error.html page and a thank you.html page.

thank you would be:

<div class="thankyou-message"><p>Thanks for your message! I will get back to you soon.<br>Namaste.</p></div> 

and error be:

<div class="error-message">
<p>The message has <em>not been sent</em>. Could you please check the following:</p>
<ul>
<li>Your name is missing</li>
<li>Your company/organization name is missing</li>
<li>Your email is missing</li>
<li>Please provide phone number or Skype username</li>
<li>Please provide short message</li>
</ul>
</div>

or, even better, i'd like to display the error or thank you messages above the contact form, on contact.html (the same page)

any help getting with this would be greatly appreciated. seriously, i'm going nuts over this.

cheers

gLocklin

11:36 am on Sep 10, 2009 (gmt 0)

10+ Year Member



see how my divs are titled: div class="thankyou-message" and div class="error-message"

by errors or successful completion, depending on which, i'd like to trigger one div class or another on the same page as the contact form - right below:


<form id="contact-form" method="post" action="/scripts/mailer2.php">

if that's not possible, i'd like to have separate pages for error messages.

cheers.

gLocklin

7:59 pm on Sep 10, 2009 (gmt 0)

10+ Year Member



solved. thanks anyway.

coopster

11:39 am on Sep 11, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], gLocklin.

Glad you got it sorted.