noob help on forms..

Man of Honour
Joined
17 Feb 2003
Posts
29,640
Location
Chelmsford
Help needed..

I'm really stuck on this. You'll have to excuse me as I'm a web building noob.

I'm trying to submit an email based on the information entered on the following form. However, I can't get it to submit the details...


http://www.admiralcomputers.co.uk/Help.shtml


I'm calling a php process from the form tag called processor.php.

<form action="" name="myform" action=processor.php>




if a put a method=post, then i get an error.

Method Not Allowed

The requested method POST is not allowed for the URL /Help.shtml.

Apache/1.3.39 Server at www.admiralcomputers.co.uk Port 80



here's the processor php >
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
mail("[email protected]","phpFormGenerator - Form submission","Form data:
First name: " . $_POST['FirstName'] . "
Surname: " . $_POST['LastName'] . "
E-Mail address: " . $_POST['Email'] . "
Phone: " . $_POST['Phone'] . "
Operating System: " . $_POST['OperatingSystem'] . "
Problem description: " . $_POST['Problem'] . "

powered by phpFormGenerator.
");
include("index.shtml");
?>

so what am I doing wrong.

Thanks

ps - the site is NOT a competitor of OCuk as no H/W or S/W is sold.
 
<form action="" name="myform" action=processor.php>

well that's invalid for a start - you only have one action and it must be in quotes..... :)

Code:
<form action="processor.php" method="post">

now if you still get $_POST errors with that, you'll need to contact your webhost. do you definitely have php support?

also your layout is busted in firefox. :p you really need to check it looks ok in as many browsers as you can. :)
 
Thanks

Ok I've just changed and uploaded that but no joy.

I'm I doing this right? If so, I'll contact the webhosters as i'm sure that the site is php enabled.

As for firefox, I have been told although I've not seen it myself yet. I've had a few tell me this but no one has given me any clues as to what's going on or how it can be fixed.
 
Its the navigation bar, it covers the main text by a few pixels. A simple padding-left of that text in the CSS will cure it

desktopru4.jpg
 
Download Firefox - you should have it installed if you're going to make websites, even if you don't want to use it as your primary browser.
 
<form action="" name="myform" action="processor.php" method="post">

well i did point that out in my first reply... :confused: :p

anyway, look at the php manual for the mail function. try using it to send mail without the form first.....

http://uk2.php.net/manual/en/function.mail.php

look at example #2....

Code:
<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

try substituting the obvious values with your own and then browse to the page through your browser.
 
Right, there must have been a delay on the webserver mail becuase they have just come down.

So sorted. Many thanks for help.. I'll get that nav bar fixed now :)
 
Trust me, I know how annoying this can be for someone starting out with PHP so, as others here have helped me before I shall attempt to help you. This is a little PHP script I created for my website which works 100% all the time and avoids spam, swearing, robots, etc.

I had an issue whereby the emails I wasn't receiving I actually found in my webmail junk box for my domain. Might be worth checking there.

Ok, here is the formprocess.php (processor.php in your case, and should be named as such).

Code:
<?php
if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
    exit("<p>This page should not be access directly</p>");
} else {
    $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i";
    $profanity = "/(type rude words here seperated by a | )/i";
    $spamwords = "/(type spam words here seperated by a |)/i";

    if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
        exit("<p>Known spam bots are not allowed.</p>");
    }
    foreach ($_POST as $key => $value) {
        $value = trim($value);

        if (empty($value)) {
            exit("<p>Empty fields are not allowed. Please go back and fill in the form.</p>");
        } elseif (preg_match($exploits, $value)) {
            exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
        } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
            exit("<p>That kind of language is not allowed through our form.</p>");
        }

        $_POST[$key] = stripslashes(strip_tags($value));
    }

    if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) {
        exit("<p>This is not a valid email address. Please press back and ammend the form.</p>");
    }

    $recipient = "[email protected]";
    $subject = "Contact From your domain";

    $message = "You've received an enquiry from: \n";
    $message .= "Name: {$_POST['name']} \n";
    $message .= "E-mail: {$_POST['email']} \n";
    $message .= "Telephone: {$_POST['telephone']} \n";
    $message .= "Enquiry: {$_POST['enquiry']} \n";
    
    $headers = "From: Admiral Computers <$recipient> \n";
    $headers .= "Reply-To: <{$_POST['email']}>";

    if (mail($recipient,$subject,$message,$headers)) {
        header ("Location: create a thank you page to redirect to");
    } else {
        header ("Location: create an error page to redirect to  ");
    }
}

?>

and this is what the html form should look like:

Code:
<form action="processor.php" method="post">

<p>Name:<input type="text" name="name" /></p>

<p>Telephone:<input type="text" name="telephone"  /></p>

<p>Email:<input type="text" name="email" /></p>

<p>Your enquiry:<textarea rows="4" cols="40" name="enquiry" ></textarea></p>

<p><input type="submit" name="submit" value="Submit Enquiry"  /></p>
</form>

There you go.
 
Back
Top Bottom