正确返回值并在表单提交后以html格式打印

How do I return the result from a post in the original html?

For example in my form, I submit an email address. After the email address is submited I would like to show that email back in a div and hide the form.

How can I do that using angularjs and php?

simple HTML form

<form name="EmailForm" class="form-horizontal" method="post" action="mail_handler.php">
    <div class="form-group form-group-lg">
        <input id="email" type="email" name="email" class="form-control size" ng-model="email.text" placeholder="me@example.com" required>
    </div>
    <div class="form-group">
        <label ng-show="EmailForm.email.$valid"><input ng-model="IAgree" name="tos" required="required" type="checkbox" /> I have read and agree to the Terms of Service</label>
    </div>
    <div class="form-group">
        <button type="submit" name="submit" ng-show="IAgree" class="btn btn-lg btn-primary">
            <span class="glyphicon glyphicon-play-circle" aria-hidden="true"></span>
            Spam me now!
        </button>
    </div>
</form>

and a simple php

<?php
if(isset($_POST['submit'])){
    $email = $_POST['email'];
    header('Location: index.html');
}
?>

If you have

$email = $_POST['email']; 
header('Location: index.html?email='.urlencode($email));

you can in index.html do

window.onload=function() {
  var email = location.search?location.search.split("email=")[1]:"";
  document.getElementById("emailId").innerHTML=decodeURIComponent(email);
}

You have two variants:

  1. You should change the action of the form to "index.php" and put all the code for the form in index.php

2.In the other variant you will use everything you have done just change header('Location: index.html'); with header('Location: index.php/?email=' . urlencode($email));

And then in index.php:

$email = $_GET['email'];
echo '<div class="email">' . $email . '</div>';

You can write both html and php in single php file. i.e form_submit.php After create php file you can write following code in form_submit file.

 <form name="EmailForm" class="form-horizontal" method="post" action="mail_handler.php">
        <div class="form-group form-group-lg">
            <input id="email" type="email" name="email" class="form-control size" ng-model="email.text" placeholder="me@example.com" required>
        </div>
        <div class="form-group">
            <label ng-show="EmailForm.email.$valid"><input ng-model="IAgree" name="tos" required="required" type="checkbox" /> I have read and agree to the Terms of Service</label>
        </div>
        <div class="form-group">
            <button type="submit" name="submit" ng-show="IAgree" class="btn btn-lg btn-primary">
                <span class="glyphicon glyphicon-play-circle" aria-hidden="true"></span>
                Spam me now!
            </button>
        </div>
    </form>

    <?php
    if(isset($_POST['submit']))
    {
    ?>
    <div>
    <?php
        $email = $_POST['email'];
    ?>
    </div>
       <style>
        .form-horizontal{display:none} 
<!-- above statement will hide form after submission of form -->
       </style>
    }
    ?>

After submit your form you will see email on same page in particular div.