dpnfxk251524 2015-10-21 08:50
浏览 42
已采纳

正确返回值并在表单提交后以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');
}
?>
  • 写回答

3条回答 默认 最新

  • drll42469 2015-10-23 12:21
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!