0

I cannot seem to get this to work properly, As far as i can see this is right? I might be doing it wrong but I am not sure, any help would be much appreciated

when i hit the submit button, nothing happens...

<div id="form" action="#" method="post"> <!-- form -->
<p class="form-title">Enquire Today!</p>
<p class="form-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.<br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.</p>
<form class="form-left"> 
<p class="form-text">Name: <input type="text" name="name"></p>
<p class="form-text">Email: <input type="text" name="email"></p>
</form>
<form class="form-right">
<p class="form-text">Phone: <input type="text" name="phone"></p>
<p class="form-text">Company: <span class="form-margin"><input type="text" name="company"></span></p>
</form>
<a class="button-enquire" type="submit" name="submit" value="Submit" href="#form">Enquire Now!</a>
</div> <!-- form -->
<?php 
if(isset($_POST['Submit'])){
    $to = "placeholder";
    $from = $_POST['email'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $company = $_POST['company'];
    $subject = " - Form submission - " . $email;
    $message = "Name: " . $name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $phone . "\n\n" . "Company: " . $company . "\n\n" . "Submitted form on the website, follow up with a call/email";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);

    }
?>

Thanks

4
  • And your error is? Commented Mar 10, 2016 at 17:41
  • nothing happens. it just doesnt do anything Commented Mar 10, 2016 at 17:41
  • @LelioFaieta Read the code buddy! Commented Mar 10, 2016 at 17:42
  • 1
    Your HTML is completely wrong and you're checking for a POST request but a form without a method submits a GET by default. Commented Mar 10, 2016 at 17:42

3 Answers 3

1

Check this it will give you basic idea how form works and you will get basic idea from following code and need more study how form works replace with your path phpfilename.php it will get php post values there. you have written method and action to div it will not work

<form id="form" action="phpfilename.php" method="post"> <!-- form -->
    <p class="form-title">Enquire Today!</p>
    <p class="form-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.<br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.</p>

    <p class="form-text">Name: <input type="text" name="name"></p>
    <p class="form-text">Email: <input type="text" name="email"></p>


    <p class="form-text">Phone: <input type="text" name="phone"></p>
    <p class="form-text">Company: <span class="form-margin">
    <input type="text" name="company"></span></p>

    <button class="button-enquire" type="submit" name="submit" value="Submit" >Enquire Now!</button>
    </form>


    <?php 
    if(isset($_POST['Submit'])){
        $to = "placeholder"; // this is your Email address  
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $company = $_POST['company'];
        $subject = " - Form submission - " . $email;
        $message = "Name: " . $name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $phone . "\n\n" . "Company: " . $company . "\n\n" . "Submitted form on the website, follow up with a call/email";
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);

        }
    ?>
Sign up to request clarification or add additional context in comments.

3 Comments

So you didn't explain the issue, and didn't even say what's changed. Man!
Changing my code by following this made it work, Thanks!
@BrendonWells Nice. Did you even consider reading my answer? :)
1

Form elements are made for a reason. It is not just you can put anything.

<a class="button-enquire" type="submit" name="submit"
   value="Submit" href="#form">Enquire Now!</a>

The above code is not a form element. Kindly replace it with either:

  • <button>
  • <input type="submit">

And it should work. Also, never ever check with isset($_POST["submit"]), as it is not reliable.

Finally your code should be:

<input class="button-enquire" type="submit" name="submit" value="Submit" />

Also make sure you replace your action attribute to the place where you are POSTing the stuff:

<form id="form" action="phpfilename.php" method="post">

And most important thing, please have only one <form> element. It looks like you are having multiple and nested <form> elements, which is invalid HTML. And most important, you have given the method and action to the <div>, where it doesn't even care those attributes.

9 Comments

how should I check if there is something in the variable/does it exist if not with isset() ?
@ksno A lot of ways: count($_POST), isset($_POST["name"])... Should I say everything?
> Also, never ever check with isset($_POST["submit"]), as it is not reliable. Why did you say that ?
I mean if you code you form correctly, not like in those questions you listed. why isnt it reliable to check if form is being submitted?
|
0

If you want to send a form with post method, then you need to set its method, like this:

<form action="target.php" method="post">
<!-- form elements -->
</form>

If you want to make sure you send something to your php backend, then you need to have input with name and value inside the form, like this:

<input type="submit" name="Submit" value="foobar">

The name will be the key and the value will be the value on server-side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.