Trying to get form to submit properly

Hi all,

I have a custom form I have created that lives in its own file. The file is linked to a WP page via a plugin called php-to-page (works great). I have this at the top of my form:

<form action=“http://www.adamsherman.com.au/postureperfection/thankyou/” method=“post”>

but when I hit the submit button I get a 404.

HOWEVER, when I copy the above url into my browser it works - I get to the right page (but without the posted info of course).

I was wondering if anyone knew why this would be happening.

You can test for yourself:

http://adamsherman.com.au/postureperfection/product-page/?prodid=323

Thanks!

Hi MeltingDog. Welcome to SitePoint. :slight_smile:

Clicking Submit on the form takes me to the thank you page (even with empty form fields, which you should avoid). It’s odd to have the tahny you url as the action link. Are you sure that’s what you want? What’s in the index file of that folder? A script?

Hi Ralph,

Thanks for the response.

Yes I havent put in any form validation yet as I am trying to get the basics of it working. Im not sure what you mean by ‘tahny you url’ I assume you mean entire URL? I have that in because I am using WP as a CMS. If I just put in /thankyou as the URL I would get:
http://adamsherman.com.au/postureperfection/product-inquiry/thankyou

instead of:

http://adamsherman.com.au/postureperfection/thankyou

There is no index file in the folder - these are actually just wordpress pages but the content links out to a script. The 2 scripts (one that has the form one the product-enquiry page and the other processes the form on the thankyou page) are within their own folder without an index as this was unnecessary. I do not think it is a html or php issue (but could be wrong) as all other html and php I have created like this works fine.

Thanks again for your reply!

OK, I obviously don’t understand how this works, but I didn’t get a 404 by clicking Submit, anyhow. When a form is submitted, do you get an email? What I meant above (sorry for the sloppy typing) was the the page referenced by the action=“” is normally a PHP script of some sort. So I would not expect the URL of the thank you page to be there normally. But maybe that’s a feature of the plugin.

Hi Ralph,

Very strange - the form seems to work for you? It just wont for me even if I clear my browsers cache and start again. Yeah I havent received any emails either - but when I paste the URL I do. Perhaps I will tear it all down and start again…very strange!

Yes … in as much as I click Submit and get the thank you message. But if you don’t get an email at the end, then presumably there’s nothing really happening, except that the form takes you to the thanks page. There must be a page at that thanks address, isn’t there? What is actually in the file at this location?

[noparse]http://www.adamsherman.com.au/postureperfection/thankyou/[/noparse]

The file at that location is as follows:

$name = $_POST[‘name’];
$email = $_POST[‘email’];
$number = $_POST[‘number’];
$comment = $_POST[‘comment’];
$pcode = $_POST[‘pcode’];
$product = $_POST[‘product’];
$amount = $_POST[‘amount’];
$formcontent=“From: $name
$email
$number
$pcode
Item: $product Amount: $amount
Message: $comment”;
$recipient = “myemail@hotmail.com”;
$subject = “Customer Enquiry from Posture Perfection Site”;
$mailheader = "From: $email \r
";
mail($recipient, $subject, $formcontent, $mailheader) or die(“Error!”);
echo “Thank You”;

I know it is not the neatest and that the thankyou string should be on its own page but I just want to get the damned thing working first!

(just to try and make it a bit clearer as to how I have done this - the ‘thankyou’ page is acutally a wordpress page with the above code ‘included()’ into the page via the php-to-page plugin - hope that makes it a little clearer!)

OK I have solved it!!!

The reason why it was working for you (I beleive) is that you were just hitting submit without filling out the fields, whilst I was filling out all the fields. When I left the fields blank it worked. I then tested all the fields and found that the Name field was causing the error. I do not know why but perhaps $name is a reserved variable. I changed it to $customer and it works fine!

Thanks for all your help Ralph!

Glad you got it sorted! :slight_smile: