-2

I want to make a contact form which I have done in HTML like this.

none of this matters i found a better way to handle this using $_SERVER["RESQUEST_METHOD"]

I'll leave it up in case anyone is as new as me and making stupid mistakes.

<!DOCTYPE html>
<html lang="en">

<body>
  <h4>Contact me!</h4>
  <form method="post" action="test_form.php" autocomplete="on">
    Subject:
    <br>
    <input type="text" name="subject" required>
    <br>name:

    <br>
    <input type="text" name="name" required>
    <br>Email:

    <br>
    <input type="email" name="email" required>
    <br>Message:

    <br>
    <textarea name="message" rows="5" maxlength="500"></textarea>
    <br>

    <input type="submit" name="submit">
  </form>
</body>

</html>

then after I add in the PHP to a separate form called test_form.php this is where I am stuck I have gone over three different layouts and formats what not and still returning the fatal error. this is my .php file I apologise for the layout. (just to add I have tried it with my variables inside the isset and I have tried them after.

<?php
$submit = $_post['submit'];
$to = "no@way.co.uk";
$header = "From:$name Email:$email /n subject:$subject";
$formcontent = "Name:$name /n Message:$message";

if (isset('submit')){

     if (empty($_post['subject'])){
         $subjectErr = "Subject is required!"
     }else{
         $subject = valid ($_post['subject']);
     }

     if(empty($_post['name'])){
         $nameErr = "Name is required!";
     }else{
         $name = valid ($_post ['name']);
     }

     if(empty($_post['email'])){
        emailErr = "Email is required!";
     }else{
        $email = valid ($_post['email']);
     }

    if(empty($_post['message'])){
       $message = "";
    }else{
       $message = valid ($_post['message']);
    }

   //function to validate data
   function valid ($data){
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
   }

   mail ($to, $subject, $formcontent, $header) or die ('error');
   echo "thank you";
}
?>

My question is where am I going wrong? I haven't even finished it yet I was just testing it to see if it was working.

grant
  • 1
  • 4
  • `isset('submit')`? What is this? – u_mulder Feb 29 '16 at 21:10
  • Please remove private information in posts. In this case `$to` – Xorifelse Feb 29 '16 at 21:17
  • a string is by definition ALWAYS set, so `isset('submit')` is pointles. isset() checks if a particular variable exists. e.g. `isset($somevar)`. you're passing in a string, which is already "set" merely by existing. – Marc B Feb 29 '16 at 21:23
  • @u_mulder i changed that and all of what you said ill edit comment in a minute. – grant Feb 29 '16 at 21:31
  • @Xorifelse will do thank you to be fair i just copied and pasted it straight from my editor completely slipped my mind. thank you. – grant Feb 29 '16 at 21:31

1 Answers1

0

According to a manual:

isset — Determine if a variable is set and is not NULL

See: variable. Do you have any variable in this:

isset('submit')

No, here's only a string "submit".

Your proper code is:

if (isset($submit))

Or simplified:

if (isset($_POST['submit']))

And by the way - it's $_POST, not $_post.

And another by the way - defining

$header = "From:$name Email:$email /n subject:$subject";

before $name, $email and $subject are defined - results in empty strings instead of real values.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • thank you, i have moved them to below the function but still in the isset. i am now getting an unexpected } on line 8. just to clarify i have done everything you said. – grant Feb 29 '16 at 21:35