首页 > 解决方案 > 在提交表单时在弹出窗口中打印 php 输出

问题描述

我想在提交 html 表单后在弹出窗口中打印 PHP 的输出。下面是我的代码示例。

<?php
 if(isset($_POST['button1']))
 {
    if("condition match")
    {
       echo "output1";
    }
    else
    {
       echo "output2";
    }
 } 
?>
<form class='n-form' action='#' method='post'>
 <div> 
  <button type='submit' name="button1" class='button'>Submit</button>
    <a href="../home.php" class="button">Cancel</a>
</div>
</form>

它应该能够根据 if 条件在弹出窗口中打印回显输出。

期待听到。

标签: phphtmlformspopup

解决方案


php中没有弹出窗口,您必须在javascript中执行

<?php
if(!empty($_POST))
{
    $text = (isset($_POST['button1'])) ? "output1" : "output2";
    echo '<script>alert("' . $text . '")</script>';
}
?>

推荐阅读