Skip to content Skip to sidebar Skip to footer

Hide Html When Submit Button Clicked, Echo Results Staying On Same Page, Email Form Results EXAMPLE PROVIDED

I searched for a basic explanation and example on how to hide my html form 'onsubmit' with basic php, while staying on the same page. I also needed to email the form results. I fou

Solution 1:

A basic structure can be something like that:

<?php
  if (isset($_POST['submit']))  {   // if submit - send email
    $you = "YOUREMAIL";
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $comment = $_REQUEST['comment'];
    mail($you, $subject, $comment, "From:" . $email);   //send email
    echo "Thank you for contacting us!";    //Email response
  }


  else  {   // else display the form:
?>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
      <label for="email">Email: 
        <input name="email" id="email" type="email" />
      </label>
      <label for="subject">Subject: 
        <input name="subject" id="subject" type="text" />
      </label>
      <label for="comment">Comment:
        <textarea name="comment" id="comment" rows="15" cols="40"></textarea>
      </label>
      <input type="submit" value="Submit" />
    </form>
<?php  } ?>

Post a Comment for "Hide Html When Submit Button Clicked, Echo Results Staying On Same Page, Email Form Results EXAMPLE PROVIDED"