PDA

View Full Version : Contact Form - Method Not Allowed Error


macsolutions
01-31-2008, 07:53 PM
I get the following message in the browser window when I click the submit button on my contact page:
Method Not Allowed The requested method POST is not allowed for the URL /Contact Us/Contact Us.html.

I have made all the pages required.

1. My script page is sendresults.php - What application do I save this file in?
2. My script is for a contact page allowing people to send email to me but all I get in my email is ( Results from form: ) and nothing else.

3. My web pages are in DW CS3 on Mac

4. My confirmation pages reside at /Confirmation/confirmation.html

5. My contact pages reside at /Confirmation/confirmation.html

<table width="380" cellspacing="2">
<tr>
<th width="63" align="right" valign="top" scope="row"><label for="CustomerName" class="style4">Name:</label></th>
<td width="425"><form action="www.macsolutions.co.uk/sendresults.php" method="post" name="Contact form" target="_self" id="Contact form">
<input name="CustomerName" type="text" id="CustomerName" size="25" maxlength="50" />
</form> </td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="CompanyName" class="style4">Company:</label></th>
<td><form id="form2" name="form2" method="post" action="">
<input name="CompanyName" type="text" id="CompanyName" size="25" maxlength="50" />
</form> </td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="EmailAddress" class="style4">Email:</label></th>
<td><form id="form3" name="form3" method="post" action="">
<input name="EmailAddress" type="text" id="EmailAddress" size="25" maxlength="50" />
</form> </td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="CommentsBox" class="style4">Comments:</label></th>
<td><form id="form4" name="form4" method="post" action="">
<textarea name="CommentsBox" id="CommentsBox" cols="35" rows="4"></textarea>
</form> </td>
</tr>
<tr>
<th align="right" valign="top" scope="row">&nbsp;</th>
<td><form id="form5" name="form5" method="post" action="">
<input type="submit" name="button" id="button" value="Submit Form" />
</form>
</td>
</tr>
</table>

<?php

// Subject of email sent to you.
$subject = 'Contact form enquirie';

// Your email address. This is where the form information will be sent.
$emailadd = 'support@macsolutions.co.uk';

// Where to redirect after form is processed.
$url = 'http://www.macsolutions.co.uk/../Confirmation/confirmation.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.'">';
?>

tux
02-01-2008, 12:10 AM
Hi Thomas,

1. You need to save your sendresults.php file in the same folder as the rest of your web pages. ie. with your index.html page.

2. Your form is all wrong. You have form tags wrap around each form element. You only need one form tag. If you are doing this in design view, start by adding a form tag, then inside the form tag build your table and then add your form elements. The action of your form should point to the sendresults.php file.

4. Your confirmation url in the sendresults.php has this ... 'http://www.macsolutions.co.uk/../Confirmation/confirmation.html'
remove this ../ .

Its late but if you have any problems post tomorrow and I'll try to help more.

Regards, Paul

Oh! When you post code highlight the code and add code tags, its the # button.

macsolutions
02-01-2008, 09:05 AM
Hi Tux,
We did it, Hoorah!
Can you take a look at the code and tell me if it needs cleaning.
I thing I should add an 'error page' what do you thing, if so would it be just a case of adding:

// Where to redirect form incase of error.
$url = 'http://www.macsolutions.co.uk/error/error.html';

I tried highlighting selecting the code and then hitting alt-3 (on the mac) but it just deleted the copy. how do I do this?

When I receive a reply in my email, on the last line I get
( Send: Contact Us ) without the quotes
How can I remove this? do I just leave the button name and value blank?


HTML FORM CODE:
<form id="form1" name="form1" method="post" action="http://www.macsolutions.co.uk/sendresults.php">
<table width="450">
<tr>
<th width="105" align="right" valign="top" scope="row"><label for="CustomerName"><span class="style4">Name</span>:</label></th>
<td width="263"><input name="CustomerName" type="text" class="textfield" id="CustomerName" size="25" maxlength="50" /></td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="CompanyName" class="style4">Company:</label></th>
<td><input name="CompanyName" type="text" class="textfield" id="CompanyName" size="25" maxlength="50" /></td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="EmailAddress" class="style4">Email:</label></th>
<td><input name="EmailAddress" type="text" class="textfield" id="EmailAddress" size="25" maxlength="50" /></td>
</tr>
<tr>
<th align="right" valign="top" scope="row"><label for="CommentReply" class="style4">Comments:</label></th>
<td><textarea name="CommentReply" cols="40" rows="4" class="textfield" id="CommentReply"></textarea></td>
</tr>
<tr>
<th align="right" valign="top" scope="row">&nbsp;</th>
<td><label for="Send"></label>
<input type="submit" name="Send" id="Send" value="Contact Us" /></td>
</tr>
</table>
</form>

PHP SCRIPT:

<?php
//--------------------------Set these paramaters--------------------------

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

// Your email address. This is where the form information will be sent.
$emailadd = 'support@macsolutions.co.uk';

// Form Address.
$url = 'http://www.macsolutions.co.uk/contact_us/contact_us.html';

// Where to redirect after form is processed.
$url = 'http://www.macsolutions.co.uk/confirmation/confirmation.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.'">';
?>


**** Please use code tags when posting code - dj ****

tux
02-01-2008, 10:03 AM
Well done Thomas,

The code looks okay to me.

With regard to an error page, I've never had a problem with a contact form once it has been set up correctly. If you need one post a new question and someone with more PHP savvy should help.

To add code tags, highlight the code and click the code button ( # ) on the text editor where you type your post, not on your keyboard.

When I receive a reply in my email, on the last line I get
( Send: Contact Us ) without the quotes
How can I remove this? do I just leave the button name and value blank?

Send is the name of the submit button and Contact Us is the value of the submit button. You have this as the script is sending you all the contents of the form. Again, someone with more PHP savvy maybe able to help if you want to not have it included when the form is submitted.

Glad to have been of help. I'm learning too and find that trying to help others helps me progress. Good luck Thomas.

Regards, Paul