Page 1 of 1

Form Post Not Working

Posted: Fri Nov 25, 2011 12:32 pm
by thomascrabs
Hi,

I've been trying to work this out for a while now but can't find any similar scenario. I taught myself PHP to build a specific website. Here is the page in question:

http://www.crabtree-confectionery.co.uk/Contact

My problem is that I can only get it to work if both <form> elements are present in the code below - if I remove the first form element it seems to post to itself or something, refreshing the page; removing the values from the form and putting the values from the form into the address bar.

Having two form elements is only a problem for IE too - seems to try and render another big section (i hate IE!)

Sorry if this has been covered or its an obvious problem - I can't get my head round it!!

Thanks for your help
Thomas

Code: Select all

<?php include 'Includes/head.php';?>

<?php include 'Includes/header.php';?>
<h1>
	Contact Us
</h1>
<div id="container">

	<div class="LeftContentLarge">
<p style="font-size:20; color:black">Interested in hiring a sweet stand?</p>
<br>
Simply contact us using one of the options below and we'll get back to you soon.<br><br>

<br>
	<table style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
	<tr>
	<td>
		<p style="color:red"><?php echo $_GET["Message"];?></p>
	</td>
	</tr>            
<tr>
<td>
<form name="form" method="post" action="Thanks"></form>
<a name="form"></a>
<form name="form1" method="post" action="Thanks"></form>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td width="16%">Telephone</td>
<td width="2%">:</td>
<td width="82%"><input name="phone" type="text" id="subject" size="50"></td>
</tr>
<tr><td>Query Type</td><td>:</td>
<td><select name="QueryType">
	<option value="">Please Select</option>
	<option value="Sweet Stand">Sweet Stand</option>
	<option value="Sweet Cart">Sweet Cart</option>
	<option value="Favours">Favours</option>
	<option value="Sweet Selections">Sweet Selections</option>
	<option value="Gifts">Gifts</option>
	<option value="Other">Other</option>
</select>
<ttd>
</tr>
<tr>
<td>Message / Comments</td>
<td>:</td>
<td><textarea name="message" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>

</td>
</tr>
</table>
<!-- Facebook Badge START --><a href="http://www.facebook.com/crabtreeconfectionery" target="_TOP" style="font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Crabtree Confectionery">Crabtree Confectionery</a><br/><a href="http://www.facebook.com/crabtreeconfectionery" target="_TOP" title="Crabtree Confectionery"><img src="http://badge.facebook.com/badge/103158849747146.324.339420737.png" style="border: 0px;" /></a><br/><a href="http://www.facebook.com/business/dashboard/" target="_TOP" style="font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Make your own badge!">Promote your Page too</a><!-- Facebook Badge END --><table class="tables" style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
		
                <tr>
                    <td>
                        <p style="color:black"><b>Phone =</b> 0778 633 2012</p>
		    </td>
                </tr>
            </table>

	
            <table class="tables" style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
                <tr>
                    <td>
                    <a id="" href="mailto:crabtree.confectionery@gmail.com">
                        <p style="color:black"><b>Email =</b>crabtree.confectionery@gmail.com</p>
                    </a>
                    </td>
                </tr>
            </table>
	</div>

</div>
<?php include 'Includes/footer.php';?>

Re: Form Post Not Working

Posted: Fri Nov 25, 2011 12:54 pm
by Celauran
action="Thanks" is definitely wrong. This should either point to a URL or be left blank. The first form and the link under it don't serve any purpose. Remove them.

Re: Form Post Not Working

Posted: Fri Nov 25, 2011 12:58 pm
by thomascrabs
The action="thanks" takes you to another page that actually sends the email and just displays a thank you message.

I'm using RewriteRule so thanks equates to Thanks,php

Removing the first form is the thing that stops everything working and means I don't get any emails from the contact form!!!!!

Re: Form Post Not Working

Posted: Fri Nov 25, 2011 12:58 pm
by Celauran
Post the contents of Thanks.php then, please. That's likely where the error lies.

Hold on. I just noticed you're closing the form immediately after opening it. Try this:

Code: Select all

<?php include 'Includes/head.php'; ?>

<?php include 'Includes/header.php'; ?>
<h1>
    Contact Us
</h1>
<div id="container">

    <div class="LeftContentLarge">
        <p style="font-size:20; color:black">Interested in hiring a sweet stand?</p>
        <br>
        Simply contact us using one of the options below and we'll get back to you soon.<br><br>

        <br>
        <table style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
               border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
            <tr>
                <td>
                    <p style="color:red"><?php echo $_GET["Message"]; ?></p>
                </td>
            </tr>            
            <tr>
                <td>
                    <form name="form1" method="post" action="Thanks">
                    <table width="100%" border="0" cellspacing="1" cellpadding="3">
                        <tr>
                            <td>Name</td>
                            <td>:</td>
                            <td><input name="name" type="text" id="name" size="50"></td>
                        </tr>
                        <tr>
                            <td>Email</td>
                            <td>:</td>
                            <td><input name="email" type="text" id="customer_mail" size="50"></td>
                        </tr>
                        <tr>
                            <td width="16%">Telephone</td>
                            <td width="2%">:</td>
                            <td width="82%"><input name="phone" type="text" id="subject" size="50"></td>
                        </tr>
                        <tr><td>Query Type</td><td>:</td>
                            <td><select name="QueryType">
                                    <option value="">Please Select</option>
                                    <option value="Sweet Stand">Sweet Stand</option>
                                    <option value="Sweet Cart">Sweet Cart</option>
                                    <option value="Favours">Favours</option>
                                    <option value="Sweet Selections">Sweet Selections</option>
                                    <option value="Gifts">Gifts</option>
                                    <option value="Other">Other</option>
                                </select>
                        <ttd>
                            </tr>
                            <tr>
                                <td>Message / Comments</td>
                                <td>:</td>
                                <td><textarea name="message" cols="50" rows="4" id="detail"></textarea></td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
                            </tr>
                    </table>
                    </form>

                </td>
            </tr>
        </table>
        <!-- Facebook Badge START --><a href="http://www.facebook.com/crabtreeconfectionery" target="_TOP" style="font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Crabtree Confectionery">Crabtree Confectionery</a><br/><a href="http://www.facebook.com/crabtreeconfectionery" target="_TOP" title="Crabtree Confectionery"><img src="http://badge.facebook.com/badge/103158849747146.324.339420737.png" style="border: 0px;" /></a><br/><a href="http://www.facebook.com/business/dashboard/" target="_TOP" style="font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Make your own badge!">Promote your Page too</a><!-- Facebook Badge END --><table class="tables" style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                                                                                                                                                                                                        border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">

            <tr>
                <td>
                    <p style="color:black"><b>Phone =</b> 0778 633 2012</p>
                </td>
            </tr>
        </table>


        <table class="tables" style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
               border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
            <tr>
                <td>
                    <a id="" href="mailto:crabtree.confectionery@gmail.com">
                        <p style="color:black"><b>Email =</b>crabtree.confectionery@gmail.com</p>
                    </a>
                </td>
            </tr>
        </table>
    </div>

</div>
<?php include 'Includes/footer.php'; ?>

Re: Form Post Not Working

Posted: Fri Nov 25, 2011 1:06 pm
by thomascrabs
Thanks for the quick reply.

Unfortunately that hasn't worked - its still just refreshing the page and posting the values to the URL instead... I've uploaded it to the site so you can try if that helps.

Here is the content of thanks.php:

Code: Select all

<?php $name = $_POST['name'];
$email = $_POST['email'];
if ($email == "") $email = "form@crabtree-confectionery.co.uk";
$message = $_POST['message'];
$phone = $_POST['phone'];
$QueryType = $_POST['QueryType'];
$mailheader = "MIME-Version: 1.0\n";
$mailheader .= "Content-type: text/plain; charset=iso-8859-1\n";
$formcontent="From: $name \n Phone: $phone \n Query Type: $QueryType \n Message: \n $message";
$recipient = "crabtree.confectionery@gmail.com";
$subject = "Crabtree Confectionery Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error! Please go back and try again. If this continues please use the email address and let us know there was a problem.");
?>
<?php include 'Includes/head.php';?>

<?php include 'Includes/header.php';?>
    <h2>
			Thanks
    </h2>
    <p>
    </p>
    <div id="container">
        <div class="leftContentLarge">
            <div class="titleContent">
            </div>
            <table class="tables" style="border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                border: 1px solid #000; padding: 10px; -webkit-box-shadow: 5px 5px 10px #000">
                <tr>
                    <td>
                        <b>Thanks for contacting us</b>
                        <br><br>
                        We will be in contact soon. 
                        <br><br>
                        If you are making a booking, we will contact you to confirm and arrange payment.
                        <br><br>
                        
                    </td>
                </tr>
            </table>
        </div>
            


<?php include 'Includes/footer.php';?>

Re: Form Post Not Working

Posted: Mon Nov 28, 2011 2:59 pm
by thomascrabs
Please can anyone help?

Please ask if you need more details...


Thomas

Re: Form Post Not Working

Posted: Mon Nov 28, 2011 5:57 pm
by McInfo
Run your page through the W3C Markup Validation Service. There are some problems with the HTML that the service will identify for you. The first thing to fix is the conflicting doctypes, which you will see if you view the HTML source of the Contact page. Also, there are nested forms.