Frank C.
Frank C.

Reputation: 8088

Extracting HTML Form TextArea in PHP

Need help in understanding why the textarea ("message" below) field in the HTML5 form is not being grabbed from the PHP code (used to create email).

HTML Code (French):

            <form method="post" action="contact.php">
                <fieldset>

                        <p class="tight" style="font-size: 10pt; text-align: center;" >Message pour des demandes de renseignements d&apos;ordre <br /> g&eacute;n&eacute;ral seulement. Veuillez utiliser demande formulaire situ&eacute; <br /> sur la page Service pour commencer.</p>

                        <label><span>Nom</span>
                        <input class="inputcontact" name="name" type="text" /></label>
                        <label><span>Courrier <br />&Eacute;lectronique</span>
                        <input class="inputcontact" name="email" type="text" /></label>
                        <label><span>T&eacute;l&eacute;phone</span>
                        <input class="inputcontact" name="telephone" type="text" /></label><br />
                        <label class="labelleft" for="message"> MESSAGE
                        <textarea name="message" rows="8" cols="45"> </textarea></label>

                </fieldset>
                <input class="submit" type="submit" value="ENVOYER" />
</form>

PHP Code (contact.php):

    <?php
/* Set e-mail recipient */
$myemail  = "[email protected]";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['name']);
$email    = check_input($_POST['email']);
$telephone  = check_input($_POST['telephone']);
$messaage  = check_input($_POST["message"]);


/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}

/* Let's prepare the message for the e-mail */
$subject ="Comment received from website";
$content = "Hello!

The contact form from the website has been submitted by:

Name: $yourname
E-mail: $email
Telephone: $telephone
Message:$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $content);

/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

Upvotes: 0

Views: 5905

Answers (3)

mineichen
mineichen

Reputation: 500

I recommend you to use filter_var($email, FILTER_VALIDATE_EMAIL); instead of your Regex. I think this would be more specific

Upvotes: 0

ProdigyProgrammer
ProdigyProgrammer

Reputation: 415

You have a typo in your variable name $message on line 9 (you wrote $messaage).

Upvotes: 0

MrSil
MrSil

Reputation: 618

$messaage  = check_input($_POST["message"]);

Message:$message.

is it ok or misspelling?

Upvotes: 3

Related Questions